Translating a systemd file to a FreeBSD rc.d script

Any idea on how to translate the systemd file below to FreeBSD in the most suitable way?

Code:
[Unit]
Description=A daemon written in Go
After=network-online.target

[Service]
User=someuser
ExecStart=/home/someuser/go/bin/daemon start
Restart=on-failure
RestartSec=3
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target
 
I wrote this a while ago: https://blog.insane.engineer/post/freebsd_daemonize/

That's what I came up with after I wanted to daemonize a go application on FreeBSD - should be similar use case as yours.
However, I don't know about all the nitty details of systemd so thigs might be more of a starting point.
Just playing around, not really familiar with systemd either and just diving into FreeBSD again. Looks like your rc.d script will do. 👍
 
Not a big systemd guru but I've dealt with some custom scripts before.

The [Unit] section has some descriptive information and shows the order (with rc(8) scripts you can do that with rcorder(8)).
The [Service] section has some information about what exactly gets started and which user account should run it. Restart stuff is not available with rc(8) but you might be able to use daemon(8) to accomplish something similar.
The [Install] section has no relation on FreeBSD. You're either in single-user mode (nothing is started) or in multi-user mode, BSD doesn't use run-levels. Default *_enable variable should be NO (not started).
 
Look at jbodenmann's writeup.

One of the things systemd does: It handles all the "daemonizing" stuff, like disconnecting from controlling terminal, cd'ing into root, and using syslog for output (instead of stdout/stderr). If your program doesn't have support for all that, use the FreeBSD's daemon program. You can also find pre-made packages for various programming languages.
 
Back
Top