What is the "right" way to ensure services restart if they go down?

I have a service running which is enabled in /etc/rc.conf, and spins up some subprocesses when it starts. Occasionally one of these subprocesses exit and the service becomes unavailable. A service … restart command brings everything back up, but requires logging in.

What is the freebsd way of ensuring this service stays available?
 
You can run the services inside the daemon command (see man 8 daemon), which has a -r option for restart. Other free good stuff you get with that: Correct disconnecting from controlling terminals, output to syslog, and the usual daemon stuff.

On the other hand, it might just be easier to write a 10-line shell script that does the loop correctly.
What is the freebsd way of ensuring this service stays available?
Don't crash in the first place.
 
There is also the issue of functional tests.

Instead of just checking that a PID still exists you do monitoring of the service and restart it when the result is not what is expected.

That's better than monitoring and invoking a human every time.
 
Back
Top