There are three common init systems used on Linux: systemd, upstart, sysv-init.
Copied from page How to find out if a system uses SysV, Upstart or Systemd initsystem:
I've collected the following solutions from various sources, mainly from topic Init script For Linux (Running NZBGet On Boot), which has become hard to follow.You can poke around the system to find indicators. One way is to check for the existence of three directories:
The thing is, these are heuristics that must be considered together, possibly with other data, not certain indicators by themselves. The Ubuntu 14.10 box I'm looking at right now has all three directories. Why? Because Ubuntu just switched to systemd from Upstart in that version, but keeps Upstart and SysV init for backwards compatibility.
- /usr/lib/systemd tells you you're on a systemd based system.
- /usr/share/upstart is a pretty good indicator that you're on an Upstart-based system.
- /etc/init.d tells you the box has SysV init in its history
In the end, I think the best answer is "experience." You will see that you have logged into a CentOS 7 box and know that it's systemd. How do you learn this? Playing around, RTFMing, etc. The same way you gain all experience.
I realize this is not a very satisfactory answer, but that's what happens when there is fragmentation in the market, creating nonstandard designs.
I didn't have a chance to test these scripts myself. If you find errors please report here in this topic and I'll update the first post. The goal is to keep the first post up-to-date.
Systemd
Create file /usr/lib/systemd/system/nzbget.service with the following content:
Code: Select all
[Unit]
Description=NZBGet Daemon
Documentation=http://nzbget.net/Documentation
After=network.target
[Service]
User=<replace_with_the_user_you_want>
Group=<replace_with_the_group_you_want>
Type=forking
ExecStart=</path/to/nzbget/nzbget> -D
ExecStop=</path/to/nzbget/nzbget> -Q
ExecReload=</path/to/nzbget/nzbget> -O
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
Upstart
Create file /etc/init/nzbget:
Code: Select all
description "NZBGet upstart script"
setuid <replace_with_the_user_you_want>
setgid <replace_with_the_group_you_want>
start on runlevel [2345]
stop on runlevel [016]
respawn
expect fork
exec </path/to/nzbget/nzbget> -D
pre-stop exec </path/to/nzbget/nzbget> -Q
SysV Init
Create file /etc/init.d/nzbget:
Code: Select all
#!/bin/sh
# Start/stop the NZBget daemon.
#
case "$1" in
start) echo -n "Start services: NZBget"
</path/to/nzbget/nzbget> -D
;;
stop) echo -n "Stop services: NZBget"
</path/to/nzbget/nzbget> -Q
;;
*) echo "Usage: $0 start|stop"
exit 1
;;
esac
exit 0
Code: Select all
chmod +x /etc/init.d/nzbget && update-rc.d nzbget defaults