What's the idiomatic way? I'd prefer the most standard and yet simple way with fewer additional dependencies. Something like an alternative to systemd of Linux.

Installed processes can be restarted automatically by adding to /etc/rc.conf

yourprocess_enable="YES"

FreeBSD System Startup for Linux Users

but that's assuming there is a start up script in /usr/local/etc/rc.d/

The FreeBSD Handbook - Starting Services

As mentioned, <service>_enable=YES in /etc/rc.conf (or relevant rc.conf.d files) will start a service on boot.

For restarting on crashes, the canonical way to do it would involve daemontools.

You can add script to cron every (in example) two minutes:

#!/bin/sh

process = 'my-secret-service' # process name

if ps ax | grep -v grep | grep $process
then
    echo "$process is alive."
else
    echo "$process is dead, but will be launched."
/usr/local/bin/my-secret-service #launch command

fi

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.