Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert SysV Init scripts to Systemd Unit File

Let's say you have a SysV Init Script named foo

  1. Copy the file to /etc/init.d/foo

  2. Enable the SysV service: chkconfig --add foo

  3. Enable the SysV service: chkconfig foo on

  4. Start the service: service foo start. After this, systemd-sysv-generator will generate this file /run/systemd/generator.late/foo.service, copy this file to /etc/systemd/system by running: cp /run/systemd/generator.late/foo.service /etc/systemd/system/foo.service

  5. Edit /etc/systemd/system/foo.service by running systemctl edit foo.service, add in the following line to foo.servie (this makes the service installable)

    [Install]
    WantedBy=multi-user.target
    
  6. Enable the service: systemd enable foo.service

  7. (Optional) You can then remove the SysV script by running chkconfig foo off && chkconfig --del foo

@poosterl

This comment has been minimized.

poosterl commented Dec 9, 2017

Hi,

I'm struggling to get this working on CentOS 7 as well as on SUSE SLES 12.
In step 4, /run/systemd/generator.late/.service is not being generated.
Apparently "systemd-sysv-generator" is nowhere to be found on the system.

Any ideas?

Tx!

@Nishen-Peiris

This comment has been minimized.

Nishen-Peiris commented Dec 14, 2017

Seems like chkconfig is no longer available on Ubuntu 16.04.

@banjodog

This comment has been minimized.

banjodog commented Jan 17, 2018

systemd enable foo.service
should read
systemctl enable foo.service

@Narimm

This comment has been minimized.

Narimm commented Jan 19, 2018

I dont quite understand how this changes things...given that the systemd script will have a line
ExecStart=/etc/init.d/foo start
ExecStop=/etc/init.d/foo stop

You are still using the init.d script

@Narimm

This comment has been minimized.

Narimm commented Jan 19, 2018

Additionally chkconfig is replaced by update-rc.d
on Ubuntu 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment