LoginSignup
2
3

More than 5 years have passed since last update.

linux > 自動起動 > /etc/rc.local (2018/03/12版) > nohupでなくsudoで実行 | 設定ミス(致命的: OS起動しなくなる)

Last updated at Posted at 2018-03-12
動作環境
CentOS 6.8 (64bit)
   - on VMWare workstation
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
date (GNU coreutils) 8.4 
tmux 1.6-3.el6

起動時にPythonスクリプトやbashスクリプトを実行する方法を見ているなか、自分の過去記事の間違いに気づいた。

line monitor > /etc/rc.local (151213)
において記載しているのは以下のようなものだった。

...
## IP address display (2015 Nov. 28)
cd /home/pi/lineMonitor/python-151127-7segLed_IPadrDisplay
nohup ./IPadrDisplay.py &

nohupを使っている。

$ man nohup | head 
NOHUP(1)                         User Commands                        NOHUP(1)



NAME
       nohup - run a command immune to hangups, with output to a non-tty

他の人の例ではsudoで&を付けて実行している。

nohupでなくsudoでの実行でいいかもしれない。

設定ミス (致命的)

( 以下を実行すると起動しなくなります。真似しないように)

sudoでの実行を試していた。

/etc/rc.local
...
sudo python /home/user/hello_180312.py &

上記の設定を間違って以下とした。

/etc/rc.local
...
sudo python /home/user/hello_180312.py

hello_180312.pyは無限ループで"hello"とprintするスクリプト。
&なしで設定したので、起動時にこれが走りOSの後の作業に遷移しなくなった。

VMWare でスナップショットを撮っていたから復旧できたが、そうでない場合は復旧をどうするか分かっていない。

WARNING
...
If your command runs continuously (perhaps runs an infinite loop) or is likely not to exit, you must be sure to fork the process by adding an ampersand to the end of the command, like so:
python /home/pi/myscript.py &
Otherwise, the script will not end and the Pi will not boot.

こういう設定変更時は機能を実行する前にダブルチェックした方がいいだろう。Think(Check) twice before you do it.

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3