Take a look under /etc/systemd/system/ This is a good place to put custom system files.
You’ll want to add your new foobar.service file here, then run systemctl daemon-reload or systemctl reload foobar to make systemd load the new config file. Then you can run systemctl start foobar and so on.
The rest is up to you and the published docs for the system file itself. My recommendation is to also try to understand daemons you may already use like nginx, apache, postgresql, etc. Their configs can be found by first running systemctl status <servicename> and to look at the Loaded: line. Most of the packaged stuff is hanging out under /lib/systemd/system.
In addition to the script you have a configuration file that defines what, when, and how. Each script has it’s own config file instead of a ‘config line’ in /etc/inittab.
How do you add a custom service to systemd? Let’s say /usr/local/sbin/foobar . I can never seem to get it to work, but can do it easily in sysvinit.
It’s been a hot minute, but here’s what I recall.
Take a look under
/etc/systemd/system/
This is a good place to put custom system files.You’ll want to add your new
foobar.service
file here, then runsystemctl daemon-reload
orsystemctl reload foobar
to make systemd load the new config file. Then you can runsystemctl start foobar
and so on.The rest is up to you and the published docs for the system file itself. My recommendation is to also try to understand daemons you may already use like nginx, apache, postgresql, etc. Their configs can be found by first running
systemctl status <servicename>
and to look at theLoaded:
line. Most of the packaged stuff is hanging out under/lib/systemd/system
.https://linuxhandbook.com/create-systemd-services/
In addition to the script you have a configuration file that defines what, when, and how. Each script has it’s own config file instead of a ‘config line’ in /etc/inittab.