/**********************************************************************
* Linux 进程退出后自动启动
* 说明:
* 在系统中,我们有时候会希望后台程序能够一直运行,即使程序出错了,
* 也是希望程序能够自动启动,并继续运行。
*
* 2016-12-10 深圳 南山平山村 曾剑锋
*********************************************************************/
一、参考文档:
How to automatically restart a linux background process if it fails?
http://superuser.com/questions/507576/how-to-automatically-restart-a-linux-background-process-if-it-fails
二、解决办法:
. 如参考文档中的说明,分三种情况:
. BusyBox init:在/etc/inittab中添加:
::respawn:/bin/myprocess
. Linux "System V" init:在/etc/inittab中添加:
myprocess::respawn:/bin/myprocess
. systemd:
. 在/etc/systemd/system/myprocess.service中添加:
[Unit]
Description=My Process
[Service]
ExecStart=/bin/myprocess
Restart=always
[Install]
WantedBy=multi-user.target
. systemctl enable myprocess.service
. 详情请参考:
http://buildroot.uclibc.org/downloads/manual/manual.html#_init_system
. systemctl start myprocess.service