I am writing my first systemd unit file.

For Type, there are a few choices: forking, simple, etc. I have read the Redhat Documentation on this topic (Table 9.9) , but still am not sure when I should use which option.

Any guidelines?


When you start the service manually from the command line (without using the nohupprefix command or the & suffix to run it in the background), what happens?

a) If the service starts and keeps running, and the prompt does not return until you press Control-C or stop the service in some other way: then Type = simple is the right choice.

b) If the prompt returns but the service keeps running in the background (i.e. the service daemonizes itself on its own), then Type = forking is the right choice.

c) If the service does its job and returns to the prompt without leaving anything running (i.e. the service just adjusts some kernel settings, sends a command to something else or does something similar), then Type = oneshot is probably the right choice. In this case, ExecStart of the service might be the command to "set" something, and ExecStop would be the corresponding command to "unset" it. This type usually benefits of RemainAfterExit=true, so systemd will keep track of the "state" of this service according to whether the thing was most recently "set" or "unset".

The other Type values are special cases. For example, if the service utilizes a D-Bus connection, then Type = dbus might be the best choice. It makes systemd aware of the fact, and then systemd will track this service (and anything that depends on it) by the presence of this service on the D-Bus.

  • Suppose I start apache,which type should be used? – kittygirl Jan 26 at 13:07
  • 1
    Well, how would you start it manually? By running apachectl start as root, perhaps? Try doing it, and see what happens. Then pick a), b) or c) from my answer. I'd bet that the prompt returns and Apache remains running, so b) would be the answer. – telcoM Jan 26 at 13:51

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.