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


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

| improve this answer | |

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.

| improve this answer | |

If you do not already have an rc.d script for your process, you can fairly easily achieve the desired result with the daemon(8) command. The command will run a child process in the background, and with the command line option -r, you can get it to restart the child process if it dies:

$ daemon -r /some/path/to/command

In later versions of FreeBSD, you can specify -R <delay in seconds> to specify how long to wait before restarting the process.

To start the process after rebooting, specify the command in the crontab(5) file like this:

@reboot daemon -r /some/path/to/command

To edit the crontab file, use

$ crontab -e
| improve this answer | |

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


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

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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