Workers
Keep long-running commands such as queue workers running for an application, and start, stop, restart, edit or delete them.
A worker is a command that ServerAvatar keeps running in the background for an application, for example a queue worker. Supervisor starts it, and restarts it if it stops. Open the application, then select Workers in its sidebar, under Settings. The screen says "Keep long-running commands running for this application. They are restarted if they stop." A link under it, "Worker output is on the server's Logs page.", opens the server's Logs.
Workers are for Git applications, Custom PHP sites, Craft CMS and Statamic sites, and Node.js applications. Any other type opens a notice: "This application type doesn't run workers."
Add a worker
-
Open Workers. A site with no workers shows "No workers yet": "A worker keeps a background process running for this application, such as a queue worker. Add one to get started."

-
Select Add worker. The dialog Add a worker asks you to choose what to Start from.

The choices depend on the site. A Laravel or Statamic site offers Queue worker ("Processes queued jobs. The usual choice.") and Horizon ("Supervises its own queue workers, with a dashboard. Use instead of a queue worker, not alongside it."). A Craft CMS site offers Queue worker. Every site offers Custom command ("Any long-running command, kept alive."). A preset fills in the command for you, using the site's PHP version.
-
Fill in the form.

- Name: for example
background-jobs. It must be different from the other workers of this application. - Command: the command to keep running. It runs directly, not through a
shell, so
;,|,&,$and similar characters are not allowed. - Processes: how many copies to run. The default is 1.
- Stop wait (seconds): how long to wait for the worker to finish when it is stopped. The default is 30. "Use at least the worker's --max-time, or a job can be killed halfway and run twice."
- Enabled, Start with supervisor, Restart if it stops and Restart after each deploy: all four start switched on.
- Name: for example
-
Open Advanced if you need more:
- Working directory (relative to the app): "Defaults to the application folder".
- Run as user: "Defaults to the application's system user".
- Log file (absolute path), for example
/var/log/my-worker.log. - Log level: Default,
critical,error,warn,info,debug,traceorblather. - Extra supervisor lines, for example
startsecs=5.
-
Select Add worker. The server starts the worker and checks that it stays running. You see "Worker saved."
If the server has no Supervisor yet, the dialog stays open with "Supervisor is being installed on the server. Try again in a few minutes." and a Try again button.
If the command exits at once, nothing is added: "This command exits straight away instead of running." and "The worker did not stay running, so it was not added. Check the command. Reference: code".
Read the list
Each worker is a row with:
- Name, with its command under it.
- State: Running, Partly running or Stopped, with "n of m running". A switched-off worker also has a Disabled badge.
- Type: Queue worker, Horizon or Custom.
- Created.

The button with the circular arrow above the table reloads the list.
For a Laravel or Statamic site the screen can also show a warning from the server.
The one it knows today is Workers cannot be restarted automatically: the site uses
the array cache driver, so after a deploy the workers keep running the old code.
Use redis, database or file instead.
Start, stop, restart, edit or delete a worker
Open the Actions menu (the three dots) on the worker's row.
- Start, Stop or Restart the worker. You see "Worker started.", "Worker stopped." or "Worker restarted."
- Edit opens Edit name, the same form with the current values. Select Save worker. The form replaces the whole worker, so what you see is what is saved. "Worker saved."
- Delete opens "Delete the worker name?" "Its processes are stopped and its configuration is removed." While the organization owner has delete protection on, you also type the worker's name. See Delete protection. You see "Worker deleted."
If an edit would make the worker exit at once, it is not saved and the worker keeps its previous command.
Node.js applications
A Node.js application also runs as a process of its own. Start, stop and restart it from the Process card on the application's Overview. See Read the overview.
A Node.js application taken over from ServerAvatar v7 can still be run by PM2. The Workers screen then shows This app is still run by PM2: "It was adopted from ServerAvatar v7. Switch it to a service ServerAvatar manages, so start, stop, restart and memory limits work here. The app restarts once."
- Select Switch to a ServerAvatar service.
- In the dialog Restart the app and switch it to a ServerAvatar service?, select Switch to a ServerAvatar service.
- You see "The app now runs as a ServerAvatar service."
Limits
- Name: up to 60 characters, one line.
- Command: up to 500 characters, one line, without
;|&`$<>(). - Processes: 1 to 16.
- Stop wait (seconds): 1 to 600.
- Working directory: up to 255 characters, without
... - Run as user: up to 32 characters, starting with a lowercase letter or
_, then lowercase letters, digits,_or-. On a managed server a worker can't run asrootorwww-data. - Log file: up to 255 characters, an absolute path starting with
/, without... - Extra supervisor lines: up to 2,000 characters, with no
[(a section header) and nouserorenvironmentline. Set the account in Run as user. The server also refusescommand,directory,stdout_logfileandstderr_logfilelines unless the panel administrator saves the worker. - A site can have a Queue worker or Horizon, not both.
Who can do this
- Seeing the list needs View on Workers (
application.worker). Without it the screen says "Your role can't view this application's workers." - Adding, editing, deleting, starting, stopping and restarting need Manage on Workers. Without it the list is read-only and shows no Actions menu.
- Switch to a ServerAvatar service needs Manage on Application
(
application). - Workers can be given in a server share and to Control Panel customers.
- Each change is recorded in the server's activity log with the worker's name, never its command. See Application activity.
Common errors
- The command field format is invalid. The command has a character that is not
allowed, such as
;or|. Use a single command with its arguments. - This name is already taken. Please choose a different name. Another worker of this application has the name.
- This application already has the other kind of queue worker. Horizon supervises its own workers, so running both means every job is handled twice. Remove the other one first.
- Workers can only run as the application's own account (user). The server refuses another Run as user.
- The directory must be inside the application's home folder (path). Change the Working directory.
- The log file must be in the application's logs folder (path). Change the Log file.
- Set the account in "Run as", not in Extra config. Remove the
userline. - The panel already sets this worker's environment. Remove the environment= line from Extra config.
- On a managed server, a worker can't run as user. Leave Run as user empty.
- Your role can't change workers. Ask an owner for manage access.
- The server isn't ready yet. Wait until the server is ready.