In the openwrt system, the init process is replaced by procd. As the parent process, procd can monitor the status of the child process. Once the child process exits, you can try to restart the process at a certain moment. There are uhttpd, netifd, etc. that are monitored by procd in the op system. There is a USE_PROCD = 1 flag in the /etc/init.d/ folder, the following describes how to let procd start a certain application. My application name is binloader, and the script code is directly added.
#! / bin / sh /etc/rc.common # Copyright (C) 2008 OpenWrt.org START = 98 #Sequence of execution, sorting according to string order is not numeric sorting USE_PROCD = 1 #Use procd to start BINLOADER_BIN = "/ usr / bin / binloader " start_service () { procd_open_instance #Create an instance, an application can see multiple instances in procd #ubus call service list You can view the instance procd_set_param respawn #Define the respawn parameters, tell procd to try when the binloader program exits restart procd_set_param command "$ BINLOADER_BIN" # binloader execution command is "/ usr / bin / binloader" , if there are later followed by the parameters can be directly procd_close_instance # closed instance } #start_service function must be redefined stop_service () { RM - f /var/run/binloader.pid } #stop_service Redefine, what to do after exiting the server restart () { stop start }
It must be pointed out that the program executed by procd cannot be a daemon daemon, because after the main process of the daemon exits, it appears to procd that the program exited, then it will enter the respawn process, and then repeatedly start and exit.
Finally failed
procd: Instance binloader::instance1 s in a crash loop 6 crashes, 0 seconds since last crash
————————————————
Original link: https://blog.csdn.net/liangdsing/java/article/details/53906445