Visor guides

Every supervisord option, explained

Each program setting, its default, and what changes when you change it.

Visor's config editor, with a program file on the left and what each line does on the right
  • supervisord
  • Laravel
  • queue workers
  • config

A supervisord program file is only a dozen lines, but each line changes how your program starts, stops, restarts or logs, and a few of the defaults catch people out. This guide goes through every setting supervisord accepts, grouped by what it controls: the default, what it does, and what happens when you change it.

The examples lean on Laravel, because queue workers are what most people run under supervisord, and the Laravel notes are set apart so you can find them. Every setting works the same for any program. The defaults come from supervisord 4.2.5’s source and its configuration docs; 4.3.0, the latest release, didn’t change any program settings.

At a glance

Every setting a [program:x] section takes, in the order this guide covers them:

Every program setting, its default and what it does
SettingDefaultWhat it does
commandnone, requiredThe program to run, with its arguments.
directorysupervisord’s folderThe folder it starts in.
usersupervisord’s userThe user it runs as.
environmentnothing addedExtra environment variables.
umasksupervisord’sThe permissions of files it creates.
numprocs1How many copies to run.
process_name%(program_name)sThe name of each copy.
autostarttrueStarts it when supervisord starts.
startsecs1How long it has to stay up to count as started.
startretries3How many failed starts before supervisord gives up.
priority999The order programs start and stop in.
autorestartunexpectedWhether it starts again when it exits.
exitcodes0The exit codes that count as expected.
stopsignalTERMThe signal that asks it to stop.
stopwaitsecs10How long to wait before killing it.
stopasgroup, killasgroupfalseWhether its child processes get the signal too.
redirect_stderrfalseWrites errors into the output log.
stdout_logfile, stderr_logfileAUTOWhere output and errors are written.
*_logfile_maxbytes, *_logfile_backups50MB, 10When logs rotate, and how many old ones to keep.
stdout_syslog, stderr_syslogfalseAlso sends output to syslog.
numprocs_start, serverurl and the event settingsvariesRarely needed.

A Laravel worker, line by line

This is the worker from Laravel’s queue docs, with full paths:

[program:acme-queue]
command=/usr/bin/php /srv/acme/artisan queue:work --sleep=3 --tries=3 --max-time=3600
directory=/srv/acme
user=forge
process_name=%(program_name)s_%(process_num)02d
numprocs=8
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stopwaitsecs=3600
redirect_stderr=true
stdout_logfile=/srv/acme/storage/logs/worker.log
What each line of the Laravel worker does
LineWhat it does
command=Runs the worker. --max-time=3600 makes each worker exit after an hour, so it starts fresh.
directory=Runs it from the app’s folder.
user=forgeRuns it as the user that owns the app. Needs supervisord to run as root.
process_name= and numprocs=8Starts eight workers, named acme-queue_00 to acme-queue_07.
autostart=trueStarts them when supervisord starts.
autorestart=trueStarts a worker again whenever it exits, including the clean exits Laravel makes on purpose.
stopasgroup=true and killasgroup=trueSends the stop signal to anything a worker started, too.
stopwaitsecs=3600Gives a running job up to an hour to finish when the worker is stopped.
redirect_stderr=true and stdout_logfile=Writes output and errors to one file.

Writing a program file

A program file is an INI file: a [program:name] line, then one setting=value per line. The name is what you type in supervisorctl start name, and it can’t contain a colon or brackets.

Where the file goes

supervisord loads the files in the folder named by files= under [include] in its main config. Most setups keep one program per file:

Where program files go
Installed withFolderFile ends in
Ubuntu or Debian package/etc/supervisor/conf.d/.conf
Homebrew (macOS)$(brew --prefix)/etc/supervisor.d/.ini
Fedora package, or anything elseThe files= line under [include]

How to write values

How to write each kind of value
KindWrite it asExample
True or falsetrue or false; yes, no, on, off, 1 and 0 work tooautostart=false
Seconds and countsA whole numberstopwaitsecs=3600
SizesA number with KB, MB or GBstdout_logfile_maxbytes=10MB
ListsValues separated by commasexitcodes=0,2
SignalsA name or a numberstopsignal=QUIT
EnvironmentKEY="value" pairs separated by commasenvironment=APP_ENV="production"

Expressions

Some parts of a value are filled in when supervisord loads the file:

  • %(program_name)s: the name after program:.
  • %(process_num)02d: the copy’s number as two digits, 00, 01 and so on. %(process_num)d gives 0, 1.
  • %(group_name)s: the name of the program’s group.
  • %(host_node_name)s: the machine’s host name.
  • %(here)s: the folder of supervisord’s main config file.
  • %(ENV_HOME)s: HOME from supervisord’s own environment. Any variable works, as %(ENV_ and its name.

Because % starts an expression, write a real % as %%, for example in a password: environment=DB_PASSWORD="pass%%word". A single % usually stops supervisord loading the config, with Format string … is badly formatted. Worse, a few, such as %s, load without an error and are replaced with other text.

Mistakes supervisord won’t warn you about

These load without a clear error, then don’t do what you meant:

Mistakes supervisord doesn’t warn about
You writeWhat happens, and what to do
stopwaitsec=3600The typo is ignored, so stopwaitsecs stays 10 and long jobs get killed. When a setting seems to do nothing, check its spelling.
command=sh -c 'php artisan migrate ; php artisan serve'Everything from a space and ; on is a comment, even inside quotes, so supervisord runs sh -c 'php artisan migrate. A space and # do the same. Put the commands in a script.
command=~/bin/worker > $HOME/worker.logThere’s no shell, so ~, $HOME, >, pipes and && aren’t understood. Use full paths, and a script for the rest; see Run it the way supervisord does.

Loading your changes

Editing a file changes nothing until supervisord loads it:

sudo supervisorctl reread
sudo supervisorctl update

reread shows what changed without doing anything. update applies it:

What each kind of change restarts
You changedRunWhat restarts
Added a program filesupervisorctl updateNothing; the new program starts if autostart=true.
Any line of a program, even a log settingsupervisorctl updateEvery copy of that program.
Removed a program filesupervisorctl updateNothing; the program stops.
A [group:x] sectionsupervisorctl updateEvery program in the group.
The [supervisord], [unix_http_server] or [inet_http_server] sectionsudo systemctl restart supervisor, or brew services restart supervisorEvery program.

supervisorctl waits for each program it restarts to stop, so with stopwaitsecs=3600, update can take as long as your longest job.

What to run

Where the program runs, as whom, and with what environment.

command

Default: none; required.

The program and its arguments. A name without a path is looked up on supervisord’s PATH, which is often shorter than your terminal’s: under brew services or systemd it has no Homebrew, nvm or pyenv folders. Use the full path, such as /usr/bin/php or /opt/homebrew/bin/php. Double quotes keep an argument with spaces together.

The program has to stay in the foreground. One that starts a copy of itself in the background and exits looks like a crash; see Programs that go to the background.

With several copies, %(process_num)02d gives each its own value, such as its own port: --port=80%(process_num)02d makes 8000, 8001 and so on.

In Laravel

The command is usually artisan queue:work, artisan horizon, artisan reverb:start or artisan octane:start, after the full path to PHP.

directory

Default: supervisord’s own working folder.

The folder the command starts in. ~ isn’t expanded here either. If the folder doesn’t exist, the program doesn’t start, and the error says couldn't chdir to and the path.

In Laravel

Set it to the app’s root, so a relative artisan works and the app finds its .env.

user

Default: the user supervisord runs as.

Runs the program as another user. Only a supervisord running as root can switch users, as the Ubuntu, Debian and Fedora packages do. Naming the user supervisord already runs as is fine. Any other user, under a supervisord that isn’t root, stops the program from starting with Can't drop privilege as nonroot user. Homebrew’s supervisord runs as you, so leave user= out on a Mac.

user= changes the user only. HOME and USER keep supervisord’s values, which under systemd means root’s. Set them with environment= when the program needs them, as Composer, git and npm do.

In Laravel

Run workers as the user that owns the app, such as forge, deploy or www-data. A worker running as root creates files in storage/, such as each day’s log file, that the web server can’t write to, and the site starts failing with Permission denied on laravel.log.

environment

Default: nothing added; the program inherits supervisord’s environment.

Extra environment variables, as KEY="value" pairs separated by commas. Quote each value, since a comma or colon in an unquoted value breaks the list, and write % as %%. They’re added on top of environment= in the [supervisord] section, which applies to every program.

environment=HOME="/home/forge",APP_ENV="production"

In Laravel

A variable set here wins over the same one in .env, because Laravel doesn’t overwrite variables that are already set. After php artisan config:cache, config values come from the cache instead, so a change here doesn’t reach them until you cache the config again.

umask

Default: supervisord’s, usually 022.

The permissions of files the program creates, as an octal number. With 022, only their owner can write to them; with 002, their group can too.

In Laravel

If the worker and the web server run as different users in the same group, umask=002 lets each write to the log and cache files the other created.

How many copies

One section can run several identical copies of a program.

numprocs

Default: 1.

Starts that many copies of the command, each watched and restarted on its own. With more than one, process_name has to contain %(process_num), or supervisord refuses the file with %(process_num) must be present within process_name when numprocs > 1.

The copies are named program:program_00, program:program_01 and so on, and program:* means all of them:

sudo supervisorctl restart acme-queue:*

What changes when you raise it:

  • Each copy is a whole process. Memory use is roughly one copy’s times numprocs; check one in ps or top before you pick a number.
  • More copies take more jobs at once, and each holds its own database and Redis connections.
  • Changing the number restarts every copy, not only the new ones.

In Laravel

numprocs is how many queue:work processes run, so it’s your queue’s concurrency. Keep it at 1 for:

  • Horizon, which starts its own workers from config/horizon.php; a second copy would start a second set.
  • The scheduler, which would run each task once per copy.
  • Reverb and Octane, which listen on one port; a second copy can’t open it and fails.

process_name

Default: %(program_name)s.

The name of each copy. With numprocs above 1, use %(program_name)s_%(process_num)02d, which gives _00, _01 and so on.

Starting

When a program starts, and when supervisord gives up on it:

start ──▶ STARTING ──(stays up for startsecs)──▶ RUNNING
             │
             └──(exits sooner)──▶ BACKOFF ──(waits 1 s, 2 s, 3 s…)──▶ STARTING
                                     │
                                     └──(after startretries + 1 tries)──▶ FATAL

autostart

Default: true.

Starts the program when supervisord starts, and when update loads it. With false, it’s loaded but stays stopped until you supervisorctl start it, which suits tools you run now and then.

startsecs

Default: 1.

How long, in seconds, a program has to stay up to count as started. If it exits sooner, the start failed, even with exit code 0. supervisorctl start waits this long before it reports the start.

  • Raise it for a program that can fail a few seconds in, for example while it connects to a database; Celery’s example uses 10. It then ends in FATAL instead of being restarted forever.
  • Set it to 0 for a program that can finish quickly on purpose.

startretries

Default: 3.

How many failed starts in a row supervisord allows before it marks the program FATAL. That’s startretries plus one tries, with a wait that grows by a second each time. A FATAL program stays stopped until you start it, even with autorestart=true.

Raise it when the program depends on something that comes up slowly after a reboot, such as Redis or a database on another machine. With startretries=10, supervisord keeps trying for about a minute. FATAL Exited too quickly covers what to do when the tries run out.

priority

Default: 999.

The order programs start and stop in. Lower numbers start first and stop last, when supervisord starts or stops and for start all and stop all. If supervisord runs Redis, give it a lower number than your workers, such as priority=100.

supervisord only sets the order; when it starts, it doesn’t wait for one program to be ready before the next. startretries still has to cover a slow start.

Restarting

What supervisord does when a program that was running exits by itself. It doesn’t apply to a program you stopped, or to failed starts, which Starting covers.

autorestart

Default: unexpected.

What autorestart does when the program exits
ValueExits with a code in exitcodesExits with any other code
falseStays stoppedStays stopped
unexpectedStays stoppedStarts again
trueStarts againStarts again

A program that stays stopped shows as EXITED.

In Laravel

Workers exit with code 0 on purpose: after --max-time, after --max-jobs, and after php artisan queue:restart. With the default unexpected, supervisord counts that as expected and leaves the worker stopped, so the first deploy that runs queue:restart stops every worker for good. Set autorestart=true, as Laravel’s example does. The same goes for Horizon after horizon:terminate.

A worker that passes its --memory limit, 128 MB by default, exits with code 12.

exitcodes

Default: 0.

The exit codes that count as expected, as a list such as 0,2. They matter only with autorestart=unexpected. Before supervisord 4.0 the default was 0,2. A one-off job that should run again only when it fails:

startsecs=0
autorestart=unexpected
exitcodes=0

Stopping

On stop, restart and update, and when supervisord itself stops, as on a reboot, supervisord:

  1. sends the program stopsignal;
  2. waits up to stopwaitsecs for it to exit;
  3. kills it with SIGKILL if it’s still running.

stopsignal

Default: TERM.

The signal that asks the program to stop: TERM, HUP, INT, QUIT, KILL, USR1 or USR2, by name or number. Use the one your program treats as a graceful stop:

The graceful stop signal of common programs
ProgramGraceful stop
Laravel queue:work and HorizonTERM, the default
CeleryTERM, the default
GunicornTERM, the default; QUIT stops at once
nginxQUIT; TERM stops at once
PHP-FPMQUIT; TERM stops at once

In Laravel

Leave it at TERM. A worker that gets TERM, INT or QUIT finishes its current job, then exits. That needs PHP’s pcntl extension; without it, the signal ends the worker in the middle of the job.

stopwaitsecs

Default: 10.

How long supervisord waits after the stop signal before it kills the program with SIGKILL, which the program can’t catch.

A higher value costs time: stop, restart, update and a deploy that restarts the program can each wait that long.

In Laravel

Set it above your longest job, as Laravel’s docs say; their example uses 3600. A job killed halfway goes back on the queue after retry_after seconds and runs again from the start. Keep the worker’s --timeout a few seconds below retry_after in config/queue.php, so a stuck job is stopped before another worker picks it up.

stopasgroup and killasgroup

Default: false; killasgroup follows stopasgroup.

  • stopasgroup=true sends the stop signal to the program and every process it started.
  • killasgroup=true does the same for the final SIGKILL only.

stopasgroup=true with killasgroup=false isn’t allowed, and supervisord refuses the file.

Turn them on when the program starts other processes and doesn’t pass the signal on: a shell script that doesn’t exec its command, npm run, a Flask or Django dev server with its reloader, or Python with multiprocessing. Without them, those processes keep running after a stop, still holding their port or taking jobs. A process that moves itself into a new process group, as daemons do, escapes them anyway.

In Laravel

The worker example turns both on. The Horizon example leaves them off, because Horizon stops its own workers.

Logs

Where a program’s output goes, and how big it gets.

redirect_stderr

Default: false.

With true, the program’s errors go to the same file as its output, like 2>&1. One file is easier to read, but you can no longer tell errors from output. Leave it off in an [eventlistener:x] section.

stdout_logfile and stderr_logfile

Default: AUTO.

Where the program’s output and errors are written:

What stdout_logfile and stderr_logfile accept
ValueWhat happens
A pathWritten to that file. Its folder has to exist, or the program won’t start. Expressions work, as in worker_%(process_num)02d.log.
AUTOA file in supervisord’s childlogdir, usually the system’s temp folder, with a name like acme-queue-stdout---supervisor-k2x9a1.log. Deleted when supervisord restarts.
NONENo file. The output is thrown away, and supervisorctl tail has nothing to show.
/dev/stdoutThe usual choice in Docker. Also set stdout_logfile_maxbytes=0, since it can’t be rotated.

Two processes mustn’t share one file while rotation is on; supervisord’s docs say the file gets corrupted when it rotates. Give each copy its own file with %(process_num)02d, or set stdout_logfile_maxbytes=0 and rotate the file with logrotate.

In Laravel

Laravel’s example has all eight workers write to one worker.log with rotation on, which is the case above; use one of the two fixes. The file holds what the worker prints, a line for each job as it runs and finishes, and PHP fatal errors. A job’s exceptions go to storage/logs/laravel.log.

Log size and backups

Default: stdout_logfile_maxbytes=50MB and stdout_logfile_backups=10, and the same for stderr_.

When a log reaches maxbytes, supervisord renames it to .1, keeps up to backups old files and starts a new one. maxbytes=0 turns rotation off, and the file grows until something else rotates it. backups=0 keeps no old files.

The limits are per file, and each copy has its own files. Eight workers with separate output and error files can use up to 8 × 2 × 11 × 50 MB, about 8.8 GB. For a chatty program:

stdout_logfile_maxbytes=10MB
stdout_logfile_backups=3

stdout_syslog and stderr_syslog

Default: false. Since supervisord 4.0.

With true, the output also goes to syslog, tagged with the program’s name. Use it when your server already collects syslog or journald.

Rarely needed

Program settings few setups need
SettingDefaultWhat it’s for
numprocs_start0The number copies count from. With numprocs_start=1 they’re _01 to _08, and --port=80%(process_num)02d starts at 8001.
stdout_capture_maxbytes, stderr_capture_maxbytes0, offCapture mode: text the program prints between supervisord’s special tags is sent to event listeners as a PROCESS_COMMUNICATION event.
stdout_events_enabled, stderr_events_enabledfalseSends each piece of output to event listeners as a PROCESS_LOG event.
serverurlAUTOThe address of supervisord passed to the program as SUPERVISOR_SERVER_URL, for programs that talk to supervisord themselves.

Every program also gets SUPERVISOR_ENABLED=1, SUPERVISOR_PROCESS_NAME and SUPERVISOR_GROUP_NAME in its environment, which a script can check to know it runs under supervisord.

Groups

A [group:x] section puts programs together, so one command starts, stops or restarts them all:

[group:acme]
programs=acme-queue,acme-horizon,acme-scheduler
priority=999
  • programs= is required: the program names, separated by commas.
  • priority= orders the group as a whole, like a program’s; 999 by default.

Grouped programs are renamed: the workers become acme:acme-queue_00 and so on, and acme:* means everything in the group. The old names, such as acme-queue:*, stop working, so update any deploy script that uses them.

Event listeners and FastCGI

Two other kinds of section take every program setting, plus a few of their own.

Event listeners

An [eventlistener:x] section runs a program that receives supervisord’s events, such as a process changing state, on its standard input. It takes every program setting except stdout_capture_maxbytes, plus:

Settings only event listeners take
SettingDefaultWhat it does
eventsnone, requiredThe events it wants, such as PROCESS_STATE, PROCESS_STATE_FATAL or TICK_60 (once a minute).
buffer_size10How many events can wait for the listener. When it’s full, the oldest is dropped.
result_handlersupervisord’s ownAlmost never changed.

Most people use the listeners in the superlance package rather than writing one. memmon restarts a program that uses too much memory:

[eventlistener:memmon]
command=memmon -g acme=256MB
events=TICK_60

Laravel workers already do this with --memory, so memmon matters more for other programs.

FastCGI programs

An [fcgi-program:x] section makes supervisord open a socket and hand it to every copy of the program, which reads it from file descriptor 0:

Settings only FastCGI programs take
SettingDefaultWhat it does
socketnone, requiredtcp://localhost:9002 or unix:///path/to/app.sock.
socket_ownerthe program’s userThe owner of a Unix socket, as user or user:group.
socket_mode0700The permissions of a Unix socket.
socket_backlogthe system’s maximumHow many connections can wait.

PHP-FPM manages its own processes, so a Laravel app doesn’t need this.

supervisord’s own settings

The [supervisord] section configures supervisord itself, and some of its settings reach every program. A change here needs supervisord restarted.

Settings in the [supervisord] section
SettingDefaultChange it when
logfilesupervisord.log in the folder it starts fromYou want supervisord’s own log somewhere else. supervisorctl maintail shows it.
logfile_maxbytes, logfile_backups50MB, 10As for program logs.
loglevelinfoA program won’t start: debug also writes programs’ output into supervisord’s log.
pidfilesupervisord.pid in the folder it starts fromYour service manager expects it elsewhere.
nodaemonfalseDocker, or anything that needs supervisord in the foreground: set true.
silentfalseIn the foreground, you don’t want its log on the terminal.
minfds1024Programs keep many files or connections open. Every program inherits the limit; Laravel’s Reverb docs suggest minfds=10000.
minprocs200Programs start many processes.
umask022supervisord’s own files need other permissions.
userno switchsupervisord starts as root but should run as another user.
directoryno changesupervisord should move to a folder when it goes to the background.
childlogdirthe system’s temp folderYou use AUTO program logs and want them kept somewhere else.
nocleanupfalseYou want AUTO logs kept when supervisord restarts.
environmentnothingEvery program needs the same variables.
strip_ansifalsePrograms print colour codes into their logs.
identifiersupervisorTools tell several supervisords apart by it.

The other sections connect supervisorctl to supervisord:

The sections that connect supervisorctl
SectionSettingsWhat it’s for
[unix_http_server]file, chmod (0700), chown, username, passwordThe socket. Who can open it decides who can run supervisorctl; see Permission denied on the socket.
[inet_http_server]port, username, passwordA TCP port instead of, or beside, the socket. Keep it on 127.0.0.1.
[supervisorctl]serverurl, username, passwordWhere supervisorctl connects. serverurl has to match the socket or port; see supervisor.sock: no such file.
[rpcinterface:supervisor]leave as the sample has itsupervisorctl needs it.
[include]filesThe program files to load: patterns separated by spaces, relative to the main config. Included files can’t include others.

Quick picks for Laravel

The settings that matter for each Laravel process
ProcessSettings that matter
queue:worknumprocs for concurrency, autorestart=true, stopwaitsecs above your longest job, stopasgroup and killasgroup, and --max-time in the command.
Horizonnumprocs=1, autorestart=true, stopwaitsecs above your longest job, as in Horizon’s docs. Restart it with php artisan horizon:terminate.
Schedulerschedule:work with numprocs=1. On a server, Laravel’s docs run schedule:run from cron instead.
Reverbnumprocs=1, and minfds raised in [supervisord]. Restart it with php artisan reverb:restart.
Octanenumprocs=1; Laravel’s docs use stopwaitsecs=3600.

Whole configs: Laravel Horizon on a Mac for Horizon, workers and the scheduler, and Celery under supervisord for Python.

With Visor

Visor knows every program setting in this guide. In a config’s Config tab, and in Add new, the explanation beside the editor says what each line does, and the checks run as you type. They catch the silent mistakes: a misspelt setting gets unknown key stopwaitsec. Did you mean stopwaitsecs? with a fix that renames it, numprocs above 1 without %(process_num) in process_name is an error, and so is a log folder that doesn’t exist. Saving shows the diff, and Save & apply writes the file and loads it, like supervisorctl update. See Program configs.

Edit this page on GitHub

The text is under CC BY 4.0: reuse it with credit to Touhidur Rahman and a link to this page. The code examples are free to copy.