Set daemon to start at boot with systemd

16,634

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.

Share:
16,634

Related videos on Youtube

Luke Moll
Author by

Luke Moll

Updated on September 18, 2022

Comments

  • Luke Moll
    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 error

    update-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 with pidof 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 are systemd and update-rc.d different systems, or does systemd just change how the latter works?

  • Luke Moll
    Luke Moll almost 8 years
    Ah 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
    nick fox over 6 years