こちらの投稿(https://teratail.com/questions/30955)を参照して、/etc/rc.local内で以下のようなフォーマットで記述したところ成功しました。
$sudo python /home/pi/HSP/hako_demo2.py &
2,3度再起動するうちに実行がされないようになりました。
起動を確認する方法は"ps -aux | grep hako_demo2.py"のように行っています。
Raspberry piを手元に3つ持っていたため再現性を確認するため同じ操作を行ったところやはり1,2回再起動した後はOS起動時に目的のファイルが自動起動されなくなりました。
また、rc.localに一緒に記述している以下の記述は問題なく起動時に動いているのでrc.localファイル自体に何かが起きている訳では無さそうです。
sudo motion
このようなケースで自動起動がされなくなる要因は何が考えられますでしょうか。
調べても手がかりになりそうなものが見つけられなかったため些細なことでもコメント頂けましたら助かります。
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
回答2件
0
YuichiKawamuraさん、
実際に書かれたrc.local
が提示されないので、実際どう書かれているかわかりませんが、コマンドを記述した際、バックグラウンドで起動し続けるものは、&
を付ける必要があります。&
をつけない場合、そのコマンドが終了後に、次の行のコマンドが実行されるので、終了しないプログラムが実行されてしまうと、次の行以降が実行されません。
- 以下の3種類でテストしてみました。(環境はRaspberryPi3B + 2018-11-13-raspbian-stretchベース+更新)
/etc/rc.local
は、systemdでは、rc-local.service
にて、実行されるので、そのステータスも確認しています。
2番目のテストでは、Starting
~~のメッセージで終わってますが、3番目では、Started
~~となっています。
- テスト :
&
なし
... python3 /home/pi/A.py > /tmp/a.txt python3 /home/pi/B.py > /tmp/b.txt exit 0
- 結果
pi@raspberrypi:~ $ systemctl status rc-local ● rc-local.service - /etc/rc.local Compatibility Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled) Drop-In: /lib/systemd/system/rc-local.service.d └─debian.conf /etc/systemd/system/rc-local.service.d └─ttyoutput.conf Active: activating (start) since Fri 2019-02-22 18:47:08 UTC; 10min ago Cntrl PID: 589 (rc.local) CPU: 266ms CGroup: /system.slice/rc-local.service ├─589 /bin/sh -e /etc/rc.local start └─599 python3 /home/pi/A.py Feb 22 18:47:08 raspberrypi systemd[1]: Starting /etc/rc.local Compatibility... Warning: rc-local.service changed on disk. Run 'systemctl daemon-reload' to reload units. pi@raspberrypi:~ $ ps aux | grep python3 root 599 0.0 0.7 11404 7444 ? S 18:47 0:00 python3 /home/pi/A.py pi 1239 0.0 0.0 4376 580 pts/0 S+ 18:57 0:00 grep --color=auto python3 pi@raspberrypi:~ $
- テスト2: 1つめ
&
あり、2つめなし
... python3 /home/pi/A.py > /tmp/a.txt & python3 /home/pi/B.py > /tmp/b.txt exit 0
- 結果
pi@raspberrypi:~ $ systemctl status rc-local ● rc-local.service - /etc/rc.local Compatibility Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled) Drop-In: /lib/systemd/system/rc-local.service.d └─debian.conf /etc/systemd/system/rc-local.service.d └─ttyoutput.conf Active: activating (start) since Fri 2019-02-22 18:58:12 UTC; 54s ago Cntrl PID: 620 (rc.local) CPU: 376ms CGroup: /system.slice/rc-local.service ├─620 /bin/sh -e /etc/rc.local start ├─626 python3 /home/pi/A.py └─627 python3 /home/pi/B.py Feb 22 18:58:12 raspberrypi systemd[1]: Starting /etc/rc.local Compatibility... Warning: rc-local.service changed on disk. Run 'systemctl daemon-reload' to reload units. pi@raspberrypi:~ $ ps aux | grep python3 root 626 0.2 0.7 11460 7224 ? S 18:58 0:00 python3 /home/pi/A.py root 627 0.3 0.7 11456 7356 ? S 18:58 0:00 python3 /home/pi/B.py pi 1135 0.0 0.0 4376 552 pts/0 S+ 18:59 0:00 grep --color=auto python3 pi@raspberrypi:~ $
- テスト3: 1つめ、2つめなとも
&
あり
... python3 /home/pi/A.py > /tmp/a.txt & python3 /home/pi/B.py > /tmp/b.txt & exit 0
- 結果
pi@raspberrypi:~ $ systemctl status rc-local ● rc-local.service - /etc/rc.local Compatibility Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled) Drop-In: /lib/systemd/system/rc-local.service.d └─debian.conf /etc/systemd/system/rc-local.service.d └─ttyoutput.conf Active: active (running) since Fri 2019-02-22 19:00:18 UTC; 2min 44s ago Process: 687 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS) CPU: 418ms CGroup: /system.slice/rc-local.service ├─693 python3 /home/pi/A.py └─694 python3 /home/pi/B.py Feb 22 19:00:18 raspberrypi systemd[1]: Starting /etc/rc.local Compatibility... Feb 22 19:00:18 raspberrypi systemd[1]: Started /etc/rc.local Compatibility. Warning: rc-local.service changed on disk. Run 'systemctl daemon-reload' to reload units. pi@raspberrypi:~ $ ps aux | grep python3 root 693 0.0 0.7 11460 7152 ? S 19:00 0:00 python3 /home/pi/A.py root 694 0.0 0.7 11460 7272 ? S 19:00 0:00 python3 /home/pi/B.py pi 1148 0.0 0.0 4376 544 pts/0 S+ 19:04 0:00 grep --color=auto python3 pi@raspberrypi:~ $
- プログラムコード
#!/usr/bin/env python3 # /home/pi/A.py import time count = 0 while True: print("A:", count) count += 1 time.sleep(1)
#!/usr/bin/env python3 # /home/pi/B.py import time count = 0 while True: print("B:", count) count += 1 time.sleep(1)
投稿2019/02/22 19:28
総合スコア1825
0
まともに考えると、単にそのコードにバグがあって、目的とする動作をしなくなっただけのようにおもわれます。
まずは、本当にそのコードが実行されていないのか、ログを出力するなどして確認してはどうでしょうか。
投稿2019/02/21 01:29
総合スコア87719
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/21 01:41
2019/02/21 01:56 編集
2019/02/21 05:20
2019/02/21 05:30
2019/02/21 05:40 編集
2019/02/21 07:14
2019/02/21 08:04 編集
2019/02/21 08:14 編集
2019/02/21 08:19
2019/02/21 08:23
2019/02/21 08:23
2019/02/21 08:29
2019/02/21 08:31
2019/02/21 08:39
2019/02/21 08:39
2019/02/21 08:43
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。