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.
Freebsd – How to automatically restart a process after a crash or reboot in FreeBsd 11
freebsdsystemd
Related Solutions
Times change and so do best practices.
The current best way to do this is to run systemctl edit myservice
, which will create an override file for you or let you edit an existing one.
In normal installations this will create a directory /etc/systemd/system/myservice.service.d
, and inside that directory create a file whose name ends in .conf
(typically, override.conf
), and in this file you can add to or override any part of the unit shipped by the distribution.
For instance, in a file /etc/systemd/system/myservice.service.d/myenv.conf
:
[Service]
Environment="SECRET=pGNqduRFkB4K9C2vijOmUDa2kPtUhArN"
Environment="ANOTHER_SECRET=JP8YLOc2bsNlrGuD6LVTq7L36obpjzxd"
Also note that if the directory exists and is empty, your service will be disabled! If you don't intend to put something in the directory, ensure that it does not exist.
For reference, the old way was:
The recommended way to do this is to create a file /etc/sysconfig/myservice
which contains your variables, and then load them with EnvironmentFile
.
For complete details, see Fedora's documentation on how to write a systemd script.
systemd-analyze
is your friend.
For example systemd-analyze critical-chain
outputs blocking tree of daemons.
Mine for example:
graphical.target @20.211s
└─multi-user.target @20.211s
└─nginx.service @19.348s +862ms
└─network.target @19.347s
└─NetworkManager.service @10.315s +9.031s
└─basic.target @10.312s
└─timers.target @10.311s
└─systemd-tmpfiles-clean.timer @10.311s
└─sysinit.target @10.295s
└─systemd-update-utmp.service @10.167s +127ms
└─systemd-tmpfiles-setup.service @10.124s +41ms
└─local-fs.target @10.097s
└─home-entd-Downloads.mount @10.093s +2ms
└─home.mount @9.326s +672ms
└─systemd-fsck@dev-sda6.service @8.472s +696ms
└─dev-sda6.device @8.471s
NetworkManager in example basically holding entire bootup.
If you want to have more detailed view you can render entire execution chain in a svg file.
systemd-analyze plot > something.svg
outputs entire chain (120+ modules) as progress bars to high-res svg file which show states, that are blocked and another problems.
Finally you have systemd-analyze dot
tool which outputs dot file which outputs entire hierarchy:
systemd-analyze dot | dot -Tpng -o stuff.png
with dot tool you can output it as ps and svg files too.
All of above tools are built-in in systemd-analyze tool which comes by default with systemd in archlinux at least. I think there is some 3rd party projects dealing with it too.
Best Answer
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