How to generate an "editable" systemd .service file from an old system-V service?

Recently, we had the issue that our home-grow "server manager" could not start a service on an "Ubuntu 16.04.1" server, because said serveice was in state "active (exited)", and not "inactive". Googling tells me I could add something like this to the service file:


But calling "systemctl edit myservice" gets me an empty file. Clearly, systemd generates some default .service file, based on the "/etc/init.d/myservice" file. Using find, I found there is a generated file under "/run/systemd/generator.late/myservice.service". But it contains a lot of stuff, which might be specific to this "run", like "Before=" and "After=" and I'm not sure if I should use it as base.

I don't want to write the .service file from scratch, since I have no knowledge about systemd .service format, and this is a running 24/7 productive server (without test-server clone I could use to "practice").

  • Don't mess with this in production. Get a test system first! Writing service files isn't that complicated, see freedesktop.org/software/systemd/man/systemd.service.html
    – Panki
    Commented Jan 8, 2020 at 12:14
  • @Panki The reason we don't have a test-system for this, is that we are missing a "monkey army" to simulate users. Setting up a copy of the server is not a problem, but without simulated users, it's kind of pointless. EDIT: The service is a load-balancer; we do have "functional" test systems, but no "load tests", so no load-balancer test server. Commented Jan 8, 2020 at 12:20
  • 1
    mysystemd.talos.sh :) Enjoy this amazing tool that a friend has builded. Commented Sep 11, 2020 at 10:40

2 Answers 2


I'm not sure if it's worth keeping this question, but a misunderstanding on my part made the question pointless.

  • My mistake was thinking that systemctl edit myservice actually edits the full .service file (as one would assume, without prior knowledge, based on the command name), and that I therefore have to write one first, before I can use this command. This is explained here.

  • Basically, systemctl edit myservice is for overriding settings, which is why it's empty by default.

  • To edit the actual file, you do systemctl edit --full myservice. And if I do that on my system-V service, I do see the full generated file.


You are using a unit generated by systemd-sysv-generator, from a van Smoorenburg rc script, most likely one with LSB header information. systemd-sysv-generator takes a one-size-fits-all approach, modified with some guesswork. van Smoorenburg rc scripts may or may not start long-running dæmon processes, may or may not employ PID files, and so forth. systemd-sysv-generator tries to generate service units that accommodate these several possibilities.

The auto-generated service units have RemainAfterExit=true when generated from van Smoorenburg rc scripts with LSB information. So when the process executing the script exits and does not leave any running processes behind, the service is still considered "active", with the service process having exited. That's what remaining after exit means. Hence, the service enters the active (exited) state.

You should stop using /etc/init.d/myservice and stop relying upon systemd-sysv-generator to wrap it in nonce service units. Make a proper, first class, service unit file.

You can start with the one that systemctl edit --full myservice gives you. But clearly that has an incorrect RemainAfterExit=true setting, for starters.

Certainly, that's also a good reason to not continue as you are and not continue relying upon an auto-generated service unit file.

Further reading

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .