Configuration of a process in Supervisor
Supervisor is a client/server system used in UNIX systems for controlling operating system processes. A few months ago we did an introduction to supervisor, where we saw some of its main features and in two previous articles we covered its installation.
Installation and Configuration of Supervisor on MacOS
Installation and Configuration of Supervisor on GNU/Linux Debian
Today we will see how to create a new process and configure it.
Creating a process
To create a process you must create a file in the supervisor process folder (you can check our installation tutorials to find this folder) with the following content.
[program:processname]
command=/path/to/executable
process_name=%(program_name)s
numprocs=1
directory=/tmp
umask=022
priority=999
autostart=true
autorestart=true
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=10
user=www-data
redirect_stderr=false
stdout_logfile=/var/log/supervisor/processname.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/supervisor/processname-error.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
serverurl=AUTO
Where:
- command
- The path of the executable that supervisor will run.
- numprocs
- Number of processes that should be running at once.
- directory
- Sets the directory from which the command will be executed.
- umask
- Specifies the umask with which the process is launched.
- autostart
- Specifies whether the service should start automatically when the supervisor starts.
- autorestart
- Defines the behavior when the service needs to be restarted. The value
true
indicates that it should always try to restart. The valueunexpected
indicates that it should only restart when an unauthorized exitcode occurs, and the valuefalse
indicates that the service should never be restarted. - exitcodes
- Defines the autorestart codes.
- startsecs
- Sets the number of seconds that must pass for the service to be considered launched correctly.
- startretries
- Number of retries to start the service before considering it failed.
- stopsignal
- Defines the signal that is sent to the process when a stop is made using the
supervisorctl
command. - user
- Sets the user with which the process is launched.
- environment
- Environment variables that will be loaded in the service execution.
- redirect_stderr
- Redirects error output to supervisord's own log instead of the individual service log.
Once the service is added, we must reload the supervisor configuration.
supervisorctl reload
Having done this, to see the status of the processes in the supervisor, we can use the following command:
supervisorctl status
Finally, to stop a service, we can use the command.
supervisorctl stop processname