Set daemon to start at boot with systemd
I don't have a Ubuntu 16.04 to test this on, or provide you with many details, but systemd has a compatibility feature to allow older /etc/init.d
scripts to continue working. Instead of using update-rc.d
to enable your daemon, use the systemd native command equivalent:
sudo systemctl enable mydaemon
If this still produces the same error, add the missing lines to the starting set of comments in your script:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
between the ### BEGIN INIT INFO
and ### END INIT INFO
lines, and try again.
See the LSB core description for these lines.
You can also explicitly start the daemon with
sudo systemctl start mydaemon
and ask for its status with
sudo systemctl status -l mydaemon
See man systemd-sysv-generator
for the compatibility feature. See this wiki for converting System V or upstart scripts like yours to native systemd Units.
Related videos on Youtube
![Luke Moll](https://i.stack.imgur.com/jAptx.png?s=256&g=1)
Luke Moll
Updated on September 18, 2022Comments
-
Luke Moll almost 2 years
I'm writing a daemon to manage my Java app on a headless Ubuntu 16.04 box using jsvc and this (probably pre-systemd) tutorial, and got as far as running
update-rc.d mydaemon enable
, receiving the errorupdate-rc.d: error: mydaemon Default-Start contains no runlevels, aborting
Having Googled around a bit this appears to have something to do with the (fairly?) recent move to
systemd
, which I have confirmed is running withpidof systemd
.How do I achieve the same starting-at-boot behaviour as
update-rc.d
(and more importantly stopping the service via/etc/init.d/mydaemon stop
rather than just killing the process as the Java app needs to clean up). And aresystemd
andupdate-rc.d
different systems, or doessystemd
just change how the latter works? -
Luke Moll almost 8 yearsAh thank you. I'd inadvertantly done this as I'd made a new systemd script in /usr/systemd but still came up with these errors. I figured since the systemd script referenced the systemv one, that's why it was causing the errors and so I added these lines in the systemv script. Didn't realise systemd was automatically converting systemv scripts into systemd ones.
-
nick fox over 6 years