3

Some of my installation scripts are using insserv, which was working fine for me on Ubuntu 16. Now on Ubuntu 18 the binary insserv is missing even though the package itself (albeit very trimmed) is there.

Is it a hard switch toward systemd init system? Strange that I couldn't find any announcement regarding unavailability of insserv on Ubuntu 18.

Felix B
  • 31
  • 2
    Ubuntu uses Système D since several years ago -- the first version to use Systemd was 15.04 in 2015; and yes, 16.04 uses Systemd. That insserv worked on 16.04 was a gracious effort from Canonical to give administrators some time to adapt. – AlexP Jun 20 '18 at 20:56

1 Answers1

3

It is not too hard to use legacy init scripts with systemd. Here is an example. Given the following SysV init script in /etc/init.d/mylittledaemon:

#!/bin/bash

### BEGIN INIT INFO
# Provides: littledaemon
# Required-Start: $remote_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Description: My little daemon
### END INIT INFO

case "$1" in
    start)
        (sleep 5000) </dev/null >/dev/null 2>&1 &
        ;;
    stop)
        pkill -f "sleep 5000"
        ;;
esac

you can enable it using systemd like this:

$ sudo chmod +x /etc/init.d/mylittledaemon
$ sudo systemctl enable mylittledaemon
mylittledaemon.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mylittledaemon

and then start it using

$ sudo systemctl start mylittledaemon

This will look at the LSB info comments and actually call update-rc.d, just like insserv did. It will also generate a transient systemd service unit using systemd-sysv-generator.

See also: http://manpages.ubuntu.com/manpages/bionic/man8/systemd-sysv-generator.8.html

The better, long-term approach would be to convert your init scripts to systemd service units. There are plenty tutorials on the net, for example this one: http://0pointer.de/blog/projects/systemd-for-admins-3.html

Sebastian Stark
  • 6,250
  • 21
  • 50
  • The only way that I’ve found to run a script as root at shutdown and reboot was based on this method. See: [https://askubuntu.com/questions/1356838/ubuntu-20-04-running-script-at-shutdown-restart] – Gabriel Coutinho De Miranda Aug 11 '21 at 07:16