###前提・実現したいこと
raspi3 でpython で書いたプログラムをOS起動時に自動実行したい。
###発生している問題・エラーメッセージ
OS起動時に自動実行されません。
/etc/systemd/system/test.service
上記ファイルを作成し、ファイルの内容は下記のとおりです。
[Unit] Description = Test [Service] ExecStart=/usr/bin/python /home/pi/nas_all/test013.py Restart=always Type=simple [Install] WantedBy=multi-user.target
その後、スタート、自動実行設定を行いました。
$ sudo systemctl start test.service $ sudo systemctl enable test.service Created symlink from /etc/systemd/system/multi-user.target.wants/test.service to /etc/systemd/system/test.service. systemctl list-unit-files --type=service
リストを見てもenableでした。
UNIT FILE STATE packagekit.service static pigpiod.service disabled plymouth-halt.service static plymouth-kexec.service static plymouth-log.service static plymouth-poweroff.service static plymouth-quit-wait.service static plymouth-quit.service static plymouth-read-write.service static plymouth-reboot.service static plymouth-start.service static plymouth-switch-root.service static plymouth.service static polkitd.service static procps.service static quotaon.service static rc-local.service static rc.local.service static reboot.service masked rescue.service static syslog.service enabled systemd-ask-password-console.service static systemd-ask-password-plymouth.service static systemd-ask-password-wall.service static systemd-backlight@.service static systemd-binfmt.service static systemd-fsck-root.service static systemd-fsck@.service static systemd-halt.service static systemd-hibernate.service static systemd-hostnamed.service static systemd-hybrid-sleep.service static systemd-initctl.service static systemd-journal-flush.service static systemd-journald.service static systemd-kexec.service static systemd-localed.service static systemd-logind.service static systemd-machined.service static systemd-modules-load.service static systemd-networkd-wait-online.service disabled systemd-networkd.service disabled systemd-nspawn@.service disabled systemd-poweroff.service static systemd-quotacheck.service static systemd-random-seed.service static systemd-readahead-collect.service disabled systemd-readahead-done.service static systemd-readahead-drop.service disabled systemd-readahead-replay.service disabled systemd-reboot.service static systemd-remount-fs.service static systemd-resolved.service disabled systemd-rfkill@.service static systemd-setup-dgram-qlen.service static systemd-shutdownd.service static systemd-suspend.service static systemd-sysctl.service static systemd-timedated.service static systemd-timesyncd.service disabled systemd-tmpfiles-clean.service static systemd-tmpfiles-setup-dev.service static systemd-tmpfiles-setup.service static systemd-udev-settle.service static systemd-udev-trigger.service static systemd-udevd.service static systemd-update-utmp-runlevel.service static systemd-update-utmp.service static systemd-user-sessions.service static test.service enabled test2.service enabled udev-finish.service static udev.service static
最初は動いていたのですが、stop,disnableや killall pythonを繰り返していたら
起動しなくなりました。
この後どのようにしたら自動実行できますでしょうか?
ご教示願います。
また、startで実行したときは実行できているのですが、プロセスで見れないのはなぜでしょうか?
pi@raspberrypi:~ $ ps u USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND pi 827 0.0 0.4 6092 4472 tty1 S+ 16:20 0:00 -bash pi 2042 0.6 0.4 5960 4388 pts/0 Ss 16:43 0:00 /bin/bash pi 2071 0.0 0.2 4220 2116 pts/0 R+ 16:43 0:00 ps u
rc.localへの記述でも実行されませんでした。
sudo python /home/pi/nas_all/test013.py exit 0
###追加
追加確認事項です。
起動時に失敗しているようです。
理由がよくわかりません。
pi@raspberrypi:~ $ sudo systemctl status test.service ● test.service - Test Loaded: loaded (/etc/systemd/system/test.service; enabled) Active: failed (Result: start-limit) since 月 2017-09-18 08:19:26 JST; 39s ago Process: 718 ExecStart=/usr/bin/python /home/pi/nas_all/test013.py (code=exited, status=1/FAILURE) Main PID: 718 (code=exited, status=1/FAILURE) 9月 18 08:19:25 raspberrypi systemd[1]: test.service: main process exited,...E 9月 18 08:19:25 raspberrypi systemd[1]: Unit test.service entered failed s.... 9月 18 08:19:26 raspberrypi systemd[1]: test.service holdoff time over, sc.... 9月 18 08:19:26 raspberrypi systemd[1]: Stopping Test... 9月 18 08:19:26 raspberrypi systemd[1]: Starting Test... 9月 18 08:19:26 raspberrypi systemd[1]: test.service start request repeate.... 9月 18 08:19:26 raspberrypi systemd[1]: Failed to start Test. 9月 18 08:19:26 raspberrypi systemd[1]: Unit test.service entered failed s.... Hint: Some lines were ellipsized, use -l to show in full.
また、プロセスには表示されていませんでした。(文字数の関係で一部略)
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND pi 1226 0.0 0.1 2344 1444 ? S 08:19 0:00 gnome-pty-helpe pi 1227 0.1 0.4 5960 4384 pts/0 Ss 08:19 0:00 /bin/bash pi 1292 0.0 0.2 4220 2184 pts/0 R+ 08:22 0:00 ps aux
手動でスタートさせると確認できました。
pi@raspberrypi:~ $ sudo systemctl start test.service pi@raspberrypi:~ $ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1384 12.4 0.9 21288 8916 ? Ssl 08:24 0:00 /usr/bin/python
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/17 23:58