1. 安装Python-PIP
1 2 3 4 | opkg update opkg install python3-pip /usr/bin/python3 -m pip install --upgrade pip pip install supervisor curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py --force-reinstall |
supervisor安装完成后,会在/usr/bin/目录生成3个可执行文件
1 2 3 4 | $ ls -lh /usr/bin/*supervisor* -rwxr-xr-x 1 root root 218 Aug 8 14:46 /usr/bin/echo_supervisord_conf -rwxr-xr-x 1 root root 223 Aug 8 14:46 /usr/bin/supervisorctl -rwxr-xr-x 1 root root 221 Aug 8 14:46 /usr/bin/supervisord |
2. 生成supervisor配置文件
1 2 3 | mkdir -p /etc/supervisor/conf.d cd /etc/supervisor/ /usr/bin/echo_supervisord_conf > ./supervisord.conf |
supervisor目录结构:
1 2 3 4 | root@OpenWrt:/etc/supervisor# tree . ├── conf.d └── supervisord.conf |
3. 修改supervisor配置文件
1 2 3 | #配置外部文件加载路径 [include] files = /etc/supervisor/conf.d/*.conf |
配置supervisor开机启动脚本
cat /etc/init.d/supervisord
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #!/bin/sh /etc/rc.common # Start/stop/restart supervisor in OpenWrt. START=91 USE_PROCD=0 PROG=/usr/bin/supervisord DAEMON=${PROG} # Location of the pid file PIDFILE=/tmp/supervisord.pid # Config of supervisor CONFIG=/etc/supervisor/supervisord.conf start_service() { # $DAEMON -c $CONFIG -j $PIDFILE procd_open_instance procd_set_param command $PROG -c $CONFIG -j $PIDFILE procd_set_param respawn procd_close_instance touch $CONFIG } stop_service() { kill $(cat $PIDFILE) } |
4. 自启supervisor
1 2 | chmod +x /etc/init.d/supervisord /etc/init.d/supervisord enable |