This article is automatically synchronized by Tencent Cloud + Community, the original address is https://stackoverflow.club/article/use_supervisor_in_ubuntu/
sudo apt install supervisor
The example is as follows, create redsocks2.conf under the directory /etc/supervisor/conf.d/, and add:
[ program:redsocks2]
command =/home/wenfeng/bin/redsocks2 -c /home/wenfeng/conf/redsocks2.conf
autostart =true
autorestart =true
redirect_stderr =true
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups =10
stdout_logfile =/var/log/supervisor/redsocks2.log
[ program:x]
: The configuration file must include at least one program, x is the name of the program, it must be written, and cannot be empty command
: contains a command to be executed when the program is started directory
: supervisord temporarily switches to this directory when executing the child process user
: account name startsecs
: The time that the process needs to keep running for the program to transition from the STARING state to the RUNNING state (unit: seconds) redirect_stderr
: If true, the stderr output of the process is sent back to supervisord on its stdout file descriptor stdout_logfile
: output process stdout to a specified file stdout_logfile_maxbytes
: stdout_logfile specifies the maximum number of bytes in the log file, the default is 50MB, you can add KB, MB, or GB, etc. stdout_logfile_backups
: the number of stdout_logfile backups to be savedIf you just put the conf
file in the /etc/supervisor/conf.d/
directory, restart supervisor
for identification
sudo service supervisor restart
Then start our program
sudo supervisorctl start awesome
If supervisor
encounters an error, you can view the log in /var/log/supervisor/supervisord.log
;
If there is a problem with the app, you can view the log in /srv/awesome/log/app.log
.
Supervisor always exits when running ssh tunnel
[ program:gpu_ssh_tunnel]
command =/usr/bin/ssh -C2qTnN -D 1080 gpu_name@gpu_domin -i /home/wenfeng/.ssh/id_rsa
autostart =true
autorestart =true
redirect_stderr =true
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups =10
stdout_logfile =/var/log/supervisor/gpu_ssh_tunnel.log
supervisorctl status display
gpu_ssh_tunnel FATAL Exited too quickly(process log may have details)
Build your own monitoring script
#! /bin/bash
whiletruedo
procnum=`ps -ef| grep 'your_name@your_domin' | grep -v grep | wc -l`if[ $procnum -eq 0];then
/usr/bin/ssh -f -C2qTnN -D 1080 your_name@your_domin -p 88-i /home/wenfeng/.ssh/id_rsa
fi
sleep 30
done
This still does not work, and the log shows Host key verification failed.
In the end, it was found that because the supervisor used the root account to run ssh, there would be a new knownhosts, so it would exit directly without entering yes to accept.
The following experiment shows that the fingerprint needs to be reconfirmed when running with sudo
sudo /usr/bin/ssh -C2qTnN -D 1080 your_name@your_domin -p your_port -i /home/wenfeng/.ssh/id_rsa
The authenticity of host '[your_name]:88 ([your_ip]:88)' can't be established.
ECDSA key fingerprint is SHA256:M/7Vo2ZjnVVc********DgkZtIjrESKMIaj/rfryfDUmqc.
Are you sure you want to continueconnecting(yes/no)? yes
The solution is to log in with the root account first, or use the designated user function of supervisor in a similar process.
Recommended Posts