Systemd using systemctl and legacy init scripts

Systemd using systemctl and legacy init scripts

I recently played with the Solus Linux distribution to check out budgie on the desktop. Solus(previously evolveOS) use systemd like most distributions now do. Of course anything I test is inside a VM and I wanted to get the Virtualbox Guest Additions to work. During the guest additions install from ISO it does complain about not knowing the distribution and for the most part when the OS is not recognized Virtualbox Guest Additions install then just stick the init scripts in /etc/init.d and let you figure it out.

Since I wanted to play with systemd a little bit here is what I did to make the guest additions scripts run at boot.  Here is a link with some comparisons between systemd and sysvinit: https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet

Lets add some units so systemctl can do its work.

$ pwd
/usr/lib/systemd/system

$ cat vboxadd.service
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/init.d/vboxadd
Description=LSB: VirtualBox Linux Additions kernel modules
Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target
Conflicts=shutdown.target

[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/init.d/vboxadd start
ExecStop=/etc/init.d/vboxadd stop

[Install]
WantedBy=multi-user.target

Ok let’s enable the unit.

$ systemctl enable vboxadd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vboxadd.service to /usr/lib64/systemd/system/vboxadd.service.

$ systemctl status vboxadd.service
● vboxadd.service - LSB: VirtualBox Linux Additions kernel modules
   Loaded: loaded (/etc/init.d/vboxadd; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)

Now start this service.

$ systemctl start vboxadd.service

And check it’s status.

$ systemctl status vboxadd.service
● vboxadd.service - LSB: VirtualBox Linux Additions kernel modules
   Loaded: loaded (/etc/init.d/vboxadd; enabled; vendor preset: enabled)
   Active: active (exited) since Thu 2015-05-14 13:39:40 CDT; 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 610 ExecStart=/etc/init.d/vboxadd start (code=exited, status=0/SUCCESS)

May 14 13:39:40 solus vboxadd[610]: Starting the VirtualBox Guest Additions ...done.

You can now do the same for the other two init scripts namely vboxadd-service and vboxadd-x11.

$ cat vboxadd-service.service
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/init.d/vboxadd-service
Description=LSB: VirtualBox Additions service
Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target
After=vboxadd.service
Conflicts=shutdown.target

[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/init.d/vboxadd-service start
ExecStop=/etc/init.d/vboxadd-service stop

[Install]
WantedBy=multi-user.target

$ systemctl enable vboxadd-service.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vboxadd-service.service to /usr/lib64/systemd/system/vboxadd-service.service.

$ systemctl start vboxadd-service.service

$ systemctl status vboxadd-service.service
● vboxadd-service.service - LSB: VirtualBox Additions service
   Loaded: loaded (/etc/init.d/vboxadd-service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2015-05-14 13:46:01 CDT; 1s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 614 ExecStart=/etc/init.d/vboxadd-service start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/vboxadd-service.service
           └─622 /usr/sbin/VBoxService

May 14 13:46:01 solus vboxadd-service[614]: Starting VirtualBox Guest Addition service  ...done.

$ cat vboxadd-x11.service
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/init.d/vboxadd-x11
Description=LSB: VirtualBox Linux Additions kernel modules

[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/init.d/vboxadd-x11 start
ExecStop=/etc/init.d/vboxadd-x11 stop

[Install]
WantedBy=multi-user.target

$ systemctl enable vboxadd-x11.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vboxadd-x11.service to /usr/lib64/systemd/system/vboxadd-x11.service.

$ systemctl start vboxadd-x11.service

$ systemctl status vboxadd-x11.service
● vboxadd-x11.service - LSB: VirtualBox Linux Additions kernel modules
   Loaded: loaded (/etc/init.d/vboxadd-x11; enabled; vendor preset: enabled)
   Active: active (exited) since Thu 2015-05-14 13:47:04 CDT; 4s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 649 ExecStart=/etc/init.d/vboxadd-x11 start (code=exited, status=0/SUCCESS)

At this point after reboot looks like systemd ran the scripts.  Let’s see if the vbox scripts/units show as a dependency for multi-user.

$ systemctl show -p "Wants" multi-user.target
Wants=systemd-logind.service systemd-update-utmp-runlevel.service NetworkManager.service dbus.service getty.target vboxadd.service vboxadd-x11.service systemd-resolved.service vboxadd-service.service remote-fs.target systemd-ask-password-wall.path systemd-user-sessions.service

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.