# Translating a systemd file to a FreeBSD rc.d script



## MasterOne (Dec 13, 2021)

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


```
[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
```


----------



## jbo (Dec 13, 2021)

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.


----------



## SirDice (Dec 13, 2021)

There are two examples of a simple script at the end of rc.d(8).


----------



## MasterOne (Dec 13, 2021)

jbodenmann said:


> 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.


----------



## SirDice (Dec 13, 2021)

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).


----------



## Erichans (Dec 14, 2021)

Also, have a look at:








						Practical rc.d scripting in BSD
					

A guide to writing new rc.d scripts and understanding those already written




					docs.freebsd.org


----------



## ralphbsz (Dec 14, 2021)

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.


----------



## grahamperrin@ (Dec 17, 2021)

Keep a daemon running on FreeBSD - Unix & Linux Stack Exchange

Amongst the points in the accepted answer: sysutils/py-supervisor/


----------

