Skip to content

Process Management

pam start runs a cluster in the foreground. When you want the application to keep running after your terminal closes, restart on crashes, rotate its logs, answer health checks and come back after a reboot, use the PAM process manager. It is built into the pam binary: think of it as a small, PHP-aware PM2.

Terminal window
pam up --name api --workers 4
pam ps
pam logs api --follow
pam reload api
pam stop api

Behind these commands runs pamd, a per-user supervisor daemon that the CLI starts on demand. Every managed application is still a normal pam start master with its own workers, so everything on Clustering applies.

Run pam up from the application directory:

Terminal window
pam up --name api --workers 4 --health-check-url http://127.0.0.1:3000/ready
Started api (PID 1024714, 4 workers)
  • The target defaults to index.php. In a Laravel project (a directory with an artisan file) and without an explicit target, PAM starts PAM Octane instead.
  • The name defaults to the directory name. Names must be unique; pam up refuses a name that already exists, online or stopped.
  • Arguments after -- belong to your application.
  • --attach keeps the application in the foreground with your terminal’s standard streams.
Option Default Description
--name NAME directory name Managed application name
--workers N available CPUs Passed to pam start
--max-requests N — Passed to pam start
--task-workers N|auto — Passed to pam start
--php-extension NAME — Repeatable extension allowlist (isolated mode)
--isolate-php-extensions off Isolate extensions even with an empty allowlist
--env-file PATH — Load environment variables from a private file (see below)
--attach off Stay in the foreground
--json off Machine-readable result
--shutdown-timeout-ms N 20000 Graceful stop deadline (100 to 300000) before a forced stop
--health-check-url URL — http:// loopback URL probed by the daemon
--health-check-interval-ms N 5000 Probe interval (250 to 3600000)
--health-check-timeout-ms N 1000 Probe timeout (50 to 5000, below the interval)
--health-check-start-period-ms N 0 Grace period after start (up to 3600000)
--health-check-failures N 3 Consecutive failures before a restart (1 to 100)
--no-autorestart autorestart on Do not restart after an unexpected exit
--restart-delay-ms N 250 First restart delay (10 to 60000)
--restart-backoff-max-ms N 15000 Backoff ceiling (up to 300000)
--max-unstable-restarts N 10 Unstable restarts before the circuit opens (1 to 100)
--min-uptime-ms N 30000 Uptime that counts as stable (1000 to 3600000)
--log-max-bytes N 10485760 Rotate a log file at this size
--log-retain N 5 Rotated files to keep (up to 100)
--memory-warning-bytes N — RSS that raises a warning in monit
--task-warning-count N — Task (thread) count that raises a warning
--memory-max-bytes N — Hard memory limit through a systemd user scope (MemoryMax)
--task-max-count N — Hard task limit through a systemd user scope (TasksMax)

--env-file loads KEY=value lines into the application’s environment. Because the file usually holds secrets, PAM only accepts a file owned by you with mode 0600 or stricter (at most 64 KiB and 256 variables):

Terminal window
chmod 600 .env.production
pam up --name api --env-file .env.production

Otherwise pam up fails with environment file must be owned by the current user and mode 0600 or stricter.

Terminal window
pam ps
NAME STATUS PID WORKERS DIRECTORY
api online 1024714 2 /srv/api

pam status NAME prints a one-line state (api is online); pam describe NAME prints the full JSON record: desired state, PIDs, worker startup timings, health-check counters, recovery state, resource policy and the paths of both log files. Add --json to ps, status and most other commands for automation.

Each application writes standard output to NAME.out.log and standard error to NAME.error.log, rotated by size.

Terminal window
pam logs api # last 100 lines of stdout
pam logs api --errors --lines 200
pam logs api --both --follow
pam logs api --query timeout --include-rotated --json
Option Description
--lines N How many lines to show (default 100; structured queries cap at 10000)
--errors Read standard error instead of standard output
--both Read both streams
--follow, -f Keep streaming new lines
--query TEXT Only lines containing TEXT (1 to 256 characters)
--include-rotated Also search rotated files
--json Emit structured entries

--follow cannot be combined with --json, --query or --include-rotated, and --errors cannot be combined with --both.

Terminal window
pam reload api # zero-downtime reload (SIGHUP to the master)
pam restart api # stop, then start again
pam scale api 12 # change the worker count (1 to 256) and restart
pam stop api # graceful stop
pam delete api # forget a stopped application

Use reload to deploy new code in place: the master boots a new generation and drains the old one only after it is ready. restart and scale restart the master. stop waits up to the application’s shutdown timeout, then forces the stop.

When a managed master exits unexpectedly, pamd restarts it. The delay starts at --restart-delay-ms, doubles after each unstable restart up to --restart-backoff-max-ms, and resets once the application has been up for --min-uptime-ms. After --max-unstable-restarts, PAM opens a circuit and waits for an explicit pam restart NAME.

With --health-check-url, pamd also probes the application over HTTP and restarts it after --health-check-failures consecutive failures. The URL must be http:// with an explicit loopback IP and port. Health checks require autorestart.

On Linux, pamd watches each master through a pidfd, so it notices a crash immediately instead of polling.

Terminal window
pam monit
PAM MONIT
NAME STATE PID WORKERS RSS_BYTES TASKS ALERT
api online 1024714 2 112717824 10 1

RSS and tasks cover the whole process tree of the application. The ALERT code is 1 healthy, 2 memory warning, 3 task warning, 4 both, 5 unavailable.

pamd samples every application once a minute and keeps the last 120 samples:

Terminal window
pam monit:history api --limit 30
pam monit:history --json
pam monit:history --record # take a sample now before printing

--memory-max-bytes and --task-max-count launch the application inside a transient systemd user scope with MemoryMax and TasksMax, so the kernel enforces them. They require /usr/bin/systemd-run. describe reports whether the cgroup limit was verified (enforcementCode 1 enforced, 2 not requested, 3 unverified).

Write a private, self-contained HTML health page of every managed application:

Terminal window
pam dashboard pam-dashboard.html

The file is created with mode 0600. For a live view, start the authenticated local dashboard. It requires a loopback address and an owner-only token file:

Terminal window
umask 077
openssl rand -hex 32 > ~/.config/pam-dashboard.token
pam dashboard:start --listen 127.0.0.1:9615 --token-file ~/.config/pam-dashboard.token
pam dashboard:status
pam dashboard:stop

127.0.0.1:9615 is the default listen address.

The CLI starts pamd automatically. You can also manage it directly:

Terminal window
pam daemon start
pam daemon status # "pamd is online (PID ...)", exit code 1 when stopped
pam daemon stop

Save the list of running applications and install a systemd user service that restores it:

Terminal window
pam save
pam startup --print # inspect the unit first
pam startup --install
systemctl --user enable --now pamd.service

pam startup --install writes ~/.config/systemd/user/pamd.service. To restore the saved list by hand, run pam resurrect. For the service to run without an open login session, enable lingering for the user (loginctl enable-linger <user>).

What Where
Records, logs, history $PAM_MANAGER_STATE_DIR, else $XDG_STATE_HOME/pam, else ~/.local/state/pam
Daemon socket $PAM_MANAGER_RUNTIME_DIR, else $XDG_RUNTIME_DIR/pam, else the state directory

To run a fully separate manager (handy for CI, or for several isolated sets of applications on one host), set both variables. With only PAM_MANAGER_STATE_DIR, the CLI still talks to the daemon listening on the default socket. pam deploy:remote sets both to give each application its own pamd:

Terminal window
export PAM_MANAGER_STATE_DIR=/srv/acme/state
export PAM_MANAGER_RUNTIME_DIR=/srv/acme/state/run
pam up --name api