Supervise a node application package, seperating deployment concerns (logging, monitoring, run-time control) from the application source.
NOTE: strong-supervisor@5 has dropped support for some legacy features that are no longer relevant to its main use-cases.
- running detached: this mode existed to provide a kindof light weight daemon, but didn't include the generation of the init.d/systemd/upstart scripts required for production usage, and those system startup tools already take care of daemonization, so the feature is being removed. Use start-stop-daemon or https://www.npmjs.com/package/strong-service-install with the strong-supervisor.
- running unclustered: this mode disabled most features of strong-supervisor but still started the agent, originally intended to report to the StrongOps service even when running apps on dev laptops, the service no longer exists, so the feature is no longer supported and needs no replacement.
sl-runctl can be installed with:
npm install -g strong-supervisor
Supervisor and its workers are monitored using appmetrics, which is open source and free for use under the Apache 2.0 license.
Note: applications wanting to use appmetrics programatically must use supervisor's builtin appmetrics, like so:
var appmetrics = global.APPMETRICS || require('appmetrics');
Note: strong-supervisor 4.x and below use strong-agent, which required a StrongLoop license. With 5.x we use appmetrics and this restriction is removed.
Appmetrics can be explicitly disabled using the
The appmetrics dashboard can
be enabled by setting the
STRONGLOOP_DASHBOARD environment variable to
See the dashboard documentation for more information.
Expensive profiling (such as object tracking or call tracing) can by dynamically started and stopped using the CLI (by worker ID or by process ID). The object count and size information is reported as a metric.
A heap snapshot can be generated for the master or any worker from the CLI (by worker ID or by process ID). It is written to a file that can be opened in the Chrome Dev Tools.
CPU profiling can be initiated on the master or any workers from the CLI (by worker ID or by process ID), and the CPU profile when stopped is written into a file that can be opened in the Chrome Dev Tools.
Supervisor will run the application clustered, by default, maintaining a worker per CPU. It does this using strong-cluster-control.
Clustering can be disabled using the
--cluster=off option, or the size can be
explicitly set to any numeric value (including
0), or to
run a worker per CPU.
Note that a number of features are unavailable when clustering is disabled.
Supervisor will load environment variable settings from a
.env file in the
applications root directory, if it exists (see
dotenv for more information).
`sl-run can be useful when launching from a shell, but is not recommended for production use. For production use it is best to run the supervisor from an init script and let the init system handle daemonization.
Supervisor collects the stdout and stderr of itself and its workers, and writes
it to stdout, by default. It is possible to specify a log file with the
Logging is most effective in cluster mode as it allows for complete capture of
the application's stdout and stderr. If the application is not "cluster safe"
but logging is still desired we recommend using
--cluster 1 to gain all of the
logging and process supervision benefits without the potential problems of
running multiple instances of your application code.
It is possible to specify per-process log files by using
%p (process ID) and
%w (worker ID) expansions in the file name. It is also possible to specify a
command to pipe log messages to by prefixing the log name with a
For example, the following will create a cluster and direct each process's logs
to a separate instance of
slr --cluster 4 --log '| logger -t "myApp worker:%w pid:%p"' myApp
Each log line captured from a worker's stdout/stderr is prefixed with a
timestamp, the process ID, and the worker ID. If the application's logs are
already prefixed with timestamps, the timestamping can be disabled with the
The supervisor log messages are prefixed with a timestamp, the supervisor's
process ID, and a worker ID of
supervisor. If the supervisor is logging to
stdout and is being captured by a logger that adds its own timestamps, these
supervisor log timestamps can be disabled with the
On platforms where syslog is supported, and when the optional strong-fork-syslog
dependency has been successfully compiled, a
--syslog option is available.
When enabled, each log line from worker stdout/stderr and the supervisor is
logged via a
syslog(3) system call. In this mode, the supervisor does NOT
timestamp the log entries, but DOES prepend process ID and worker ID since
the system call is performed by the supervisor, preventing the standard syslog
PID stamping from being accurate.
The log file can be rotated with
SIGUSR2, see Signal Handling below.
Supervisor can optionally write a PID file with the master's PID. This could be
useful to send signals to a detached process from within system startup scripts
as used by
The supervisor will attempt a clean shutdown of the cluster before exiting if it is signalled with SIGINT or SIGTERM, see control.stop().
If the supervisor is logging to file, it will reopen those files when signalled with SIGUSR2. This is useful in conjunction with tools like logrotate.
If the supervisor is clustered, it will attempt a restart of the cluster if it is signalled with SIGHUP, see control.restart().
usage: sl-runctl [options] [command] Options: -h,--help Print this message and exit. -v,--version Print version and exit. -C,--control <CTL> Control endpoint for process runner (default `runctl`). Commands: status Report status of cluster workers, the default. set-size <N> Set cluster size to N workers. stop Stop, shutdown all workers and stop controller. restart Restart, restart all workers. ls [DEPTH] List application dependencies. objects-start <ID> Start tracking objects on ID. objects-stop <ID> Stop tracking objects on ID. Object metrics are published, see the `--metrics` option to `sl-run`. cpu-start <ID> [TIMEOUT] Start CPU profiling on ID. TIMEOUT is the optional watchdog timeout, in milliseconds. In watchdog mode, the profiler is suspended until an event loop stall is detected; i.e. when a script is running for too long. Only supported on Linux. cpu-stop <ID> [NAME] Stop CPU profiling on ID, save as "NAME.cpuprofile". CPU profiles must be loaded into Chrome Dev Tools. The NAME is optional, profiles default to being named `node.<PID>.cpuprofile`. heap-snapshot <ID> [NAME] Snapshot heap objects for ID, save as "NAME.heapsnapshot". Heap snapshots must be loaded into Chrome Dev Tools. The NAME is optional, snapshots default to being named `node.<PID>.heapshapshot`. patch <ID> <FILE> Apply patch FILE to ID. env-get [ID] Get the complete environment of the specified process. If no target is specified the default is 0, the cluster master process. env-set <K1=V1...> Set environment variables in master and worker. Changes are live without process restart. env-unset <KEYS...> Unset environment variables in master and workers. Changes are live without process restart. Commands specific to a worker ID accept either a process ID or cluster worker ID, and use an ID of `0` to mean the cluster master.
strong-supervisor uses a dual license model.
You may use this library under the terms of the Artistic 2.0 license.