alxpanel

Background processes

Programs that an account keeps running all the time, such as a queue worker or a Node.js server.

What they are for

A website's PHP runs only while a visitor's request is being answered, and a cron job runs at set times and ends. Some programs fit neither: they have to be running all the time.

A background process is one such command. The server starts it, keeps it running, starts it again when it exits and starts it after a reboot.

Allowing them

Processes are part of the plan. Background processes on the plan form is the number of processes each account may have; it is 0 on a new plan, which switches the feature off.

Creating one

Field Meaning
Name Lowercase letters, digits and dashes, up to 32 characters, unique in the account. alxpanel-process uses this name.
Site A process belongs to one of the account's sites and runs in that site's folder. An account without an active site cannot have one.
Folder inside the site Optional. The command runs in this folder, for example current when deploys switch a current link to the newest release.
Command One shell command line, with the same rules as a cron job's command.
Needs a port The panel gives the process a port. See Ports.

The On switch stops and starts a process without deleting it.

How a process runs

When the command exits for any reason, the server starts it again: after 2 seconds the first time, then after longer waits, up to 60 seconds between attempts. It never gives up, so a command that fails at once stays in Restarting until it is fixed or switched off.

Stopping or restarting a process stops every program the command started. One that has not ended after 15 seconds is killed.

What the Process column says

Shown Meaning
Running since 14:05 The command is running.
Restarting — exit 1, 7 restarts The command exited and the server is waiting to start it again. The exit code is the command's own; View log shows what it printed. Exit code 200 means that the folder does not exist.
Stopped Switched off, or the account is suspended.
Port … is in use Another program on the server is listening on this process's port, so the process cannot start. It starts by itself once that program is gone.
status unavailable The panel could not ask the server just now.

A command that fails right after it starts shows Running for a moment between two Restarting reads.

Ports

With Needs a port on, the panel assigns the lowest free port between 20000 and 29999. The port is unique on the server and is never typed in. The process gets it in the PORT environment variable and should listen on 127.0.0.1.

The port is private to the account:

The port is freed when the process is deleted or Needs a port is switched off, and may then go to another process.

Logs

View log shows the newest 1000 lines of what the process wrote to standard output and standard error. A process that writes more than 1000 lines in 30 seconds loses the rest for that period.

Restarting after a deploy

A worker keeps the code it started with, so a deploy has to restart it. Restart on the page does that; from a deploy script, the account's user runs:

alxpanel-process restart queue

See alxpanel-process.

What else stops or restarts a process

Event Effect
The account is suspended Every process is stopped. Unsuspending starts those that were switched on.
The site is deleted Its processes are deleted with it.
The account is deleted Its processes are deleted.
The server reboots Every switched-on process starts again.
alxpanel is updated Processes keep running. A release that changes how processes are run restarts each one once.

Example: Inertia SSR

  1. Make the server in ssr.js listen on the given port: createServer(page => …, { port: process.env.PORT }).
  2. Create a process with the command node bootstrap/ssr/ssr.js and Needs a port on.
  3. The Port column shows the number. Put INERTIA_SSR_URL=http://127.0.0.1:<port> in the site's .env.