I just upgraded from Ubuntu server 14 to version 15. I had trouble getting my upstart script working after the upgrade, and read that systemd is the new default. I'm far from a linux expert, so please go easy on me :-)
Here is what my upstart script was before:
description "NZBGet upstart script"
setuid robert
setgid robert
start on runlevel [2345]
stop on runlevel [016]
respawn
expect fork
script
exec nzbget -D
end script
pre-stop script
exec nzbget -Q
end script
Based on the upstart to systemd wiki page, I used the tables provided there to map things as closely as I could in my new systemd service file:
[Unit]
Description=NZBGet Service
[Service]
Type=forking
ExecStart=/usr/local/bin/nzbget -D
ExecStop=/usr/local/bin/nzbget -Q
Restart=on-failure
This file is located at /home/robert/.config/systemd/user/nzbget.service
. To start the service manually, I've been doing:
$ systemctl --user start nzbget
This works great. However, when I log out of my SSH session, the service shuts down. Also, it does not start on bootup or user login. I want it to behave the same as it did as an upstart service: I want it to start at boot, run constantly, and as a specific user.
What do I need to do to get this configuration?
systemctl enable
command though, this was not obvious to me at first. Also enabling gave me some warning about a missing[Install]
section. I ignored it, but I'm not sure if it will impact its ability to start at boot time. – void.pointer Sep 19 '15 at 17:28Install
warning was actually really important. It won't start on boot withoutWantedBy=multi-user.target
under the[Install]
section. After adding this to the.service
file, then you canenable
it. – void.pointer Oct 11 '15 at 02:37[Install]
section. Hope it's now more helpful for anyone looking for it. – Yamaho Feb 18 '16 at 19:50something@.service
thenenable
d likesomething@username.service
the setting becomesUser=%i
meaning the user is not hard-coded and multiple users can use the same definition. An example. – Walf May 06 '17 at 12:38/etc/systemd/user/
? – Khurshid Alam Sep 04 '17 at 13:50/usr/local/lib/systemd/system
and you runsystemctl enable [service]
, which links them into/etc/systemd/system
. You're not supposed to drop files in/etc/systemd/system
. See:man systemd
and look under DIRECTORIES – fbicknel Dec 17 '19 at 13:11/etc/systemd/user/
where system-wide user units are placed by the system administrator." (not that there is necessarily a universal truth value here ... I would just like to do it in the most straightforward way for myself) – some bits flipped Jun 13 '20 at 22:22robert
to have a user servicenzbget.service
located at their~/.config/systemd/user/nzbget.service
.robert
can then enable this service withsystemctl --user enable nzbget
. – Abdull Nov 02 '22 at 10:59