sudo apt-get install supervisor
sudo nano /etc/supervisor/conf.d/ir_sensor.conf
more /var/log/supervisor/supervisord.log
ir_sensor.conf 内容
[program:ir_sensor]
command = bash -c "sleep 60 && python main.py"
directory = /home/pi/Infrared_sensor
user = pi
startsecs = 3
redirect_stderr = true
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups = 10
stdout_logfile = /home/pi/Infrared_sensor/ir_sensor.log
directory 代表cd 到这个目录下
command 代表执行的命令,这里是先延时60秒,在运行python main.py
stdout_logfile 代表log文件的位置
关闭supervisor
sudo /usr/bin/supervisorctl stop all
手动打开supervisor
sudo /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
遇到报错:
问题1:
Unlinking stale socket /tmp/supervisor.sock
或者:
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
解决办法:
sudo unlink /tmp/supervisor.sock
or
sudo unlink /var/run/supervisor.sock