Saturday, 25 March 2023

Install and manage Supervisor with example

1. Install supervisor

# install supervisor
sudo apt update && sudo apt install supervisor 
# check supervisor status
sudo systemctl status supervisor

2. Add demo program runDate.sh

# create file runDate.sh
nano runDate.sh 
 
# with content
#!/bin/bash
while true
do
# Echo current date to stdout
echo $(date)
sleep 1
done
 
# set exec for runDate.sh
chmod +x ~/
runDate.sh

3. Configure supervison for program runDate.sh

# create & open runDate.conf
sudo nano /etc/supervisor/conf.d/runDate.conf
 
# content file runDate.conf
[program:runDate]
command=/bin/bash /home/phong/runDate.sh
autostart=true
autorestart=true
stderr_logfile=/home/phong/runDate.err.log
stdout_logfile=/home/phong/runDate.out.log

- autostart = true; // the program started when system boots
- autorestart = true; // restart program after it exits
- stderr, stdout // write err, out for program

4. Using supervisor

# reload the configuration file
sudo supervisorctl reread 
# applies the changes made to the supervisor configuration file
sudo supervisorctl update

# view the last few lines of runDate.out.log
sudo tail /var/log/runDate.out.log 
# show all processes suppervisor managing
sudo supervisorctl
# start mange process of program
supervisor> start runDate
 
# stop mange process of program
supervisor> stop runDate
# show all processes
supervisor> status

# exit the supervisorctl
supervisor> quit
# show all cmd in supervisor
supervisor> help

Thank you 



No comments:

Post a Comment

Golang Advanced Interview Q&A