pipe-tools
Software
www.skarnet.org

The npt-supervise program

npt-supervise starts and monitors a service. It is an enhanced version of the supervise command.

Interface

     npt-supervise s

Control

npt-supervise listens on the ./supervise/control named pipe. When some external program, like npt-svc or svc, writes on that pipe, npt-supervise reads the bytes one by one and interprets them as control commands. Unknown commands are ignored. The valid commands are the following:
u
Up. The service is marked wanted up. If it is not running, start it. It will be automatically restarted when it exits.
d
Down. The service is marked wanted down. If the service is running, send it a SIGTERM. If it was paused, send it a SIGCONT too. Do not restart it when it exits.
o
Once. The service is marked wanted down, but if it is not running, start it once.
t
Terminate. If the service is running, send it a SIGTERM.
p
Pause. If the service is running, send it a SIGSTOP.
c
Continue. If the service is running, send it a SIGCONT.
a
Alarm. If the service is running, send it a SIGALRM.
b
Abort. If the service is running, send it a SIGABRT.
q
Quit. If the service is running, send it a SIGQUIT.
h
Hangup. If the service is running, send it a SIGHUP.
i
Interrupt. If the service is running, send it a SIGINT.
k
Kill. If the service is running, send it a SIGKILL.
1
User-defined 1. If the service is running, send it a SIGUSR1.
2
User-defined 2. If the service is running, send it a SIGUSR2.
f
Enable "finish". Try and spawn ./finish everytime ./run exits. This is the default if ./finish exists and is executable at the time npt-supervise is run.
F
Disable "finish". Do not spawn ./finish everytime ./run exits. This is the default when ./finish does not exist or is not executable at the time npt-supervise is run.
x
Exit. Exit 0 as soon as the service is down and wanted down.

Signals

When npt-supervise receives a SIGTERM, it behaves as if it had received an x command.

Notification

When npt-supervise monitors a service directory s, it performs the following actions: event is a fifodir; if it doesn't exist, npt-supervise doesn't mind.

You can then use npt-wait, npt-and or npt-or on supervise/event to be instantly notified when one of those events arises.

Be careful! Do NOT run a command line like

 npt-svc -d /service/zoinx ; npt-and /service/zoinx/supervise/event d
or you will suffer from an important race condition. Use the npt-svwaitdown command instead: it checks the status file while listening, avoiding the race.

Restarting policy fine-tuning with ./finish

You can use those values in your ./finish script to perform different actions, for instance, when your ./run script exits zero, exits non-zero, or is killed by a signal. Typically, ./finish can be used to send a mail to the system administrator whenever a service crashes.

Be careful: npt-supervise will not restart ./run as long as ./finish has not exited, so you should make sure that ./finish does not block indefinitely.

Compatibility

Credits