NAME

unix::residentevil — Create a server process that can survive hangs and crashes.

synopsis

wyrm::unix::residentevil [ time-out ]

wyrm::unix::alive

wyrm::unix::bitethehand

description

Fork the process into a master and slave. The master process does not return; instead it enters a loop that monitors the slave process. If the slave dies or does not give a keep alive signal for any period more than time-out seconds (default is 10), the slave is killed and the master forks a new slave. It continues to restart the slave until the master is exitted on signal.

All open channels in the interpretter are flushed prior to the fork.

The slave must evaluate wyrm::unix::alive within every time-out seconds. Failure to do so will be interpretted that the slave is hung; it will be killed and a new slave process started.

The slave can signal the master with wyrm::unix::bitethehand to bite the hand that feeds it; that send a SIGTERM to the master and terminates both master and slave. If the slave simply exits without signalling the master, it will be restarted.

When the slave is started or restarted, it appears to returns from the command with the list time-out, process id of the master, the number of times the slave has been started (from 1), and the reason for this start:

0
This is the first execution of the slave.
1
The previous slave exitted; the exit code is the next element.
2
The previous slave terminated with a signal; the signal number is the next element.
3
The slave was hung and killed.

CAVEATS

residentevil is not thread safe.