Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should the option RemainAfterExit needs to be set true when creating new systemd services?

I am trying to write a few services. Some of them have 'type' option set to oneshot. But i am still confused when the option 'RemainAfterExit' needs to be set true. (not just that service needs to be active even after exiting).

like image 605
Aditya Vardhan Avatar asked Jun 28 '16 09:06

Aditya Vardhan


People also ask

What option in the service section of a unit configuration file specifies the command that is executed when the service is started?

ExecStart= : This specifies the full path and the arguments of the command to be executed to start the process.

What is systemd RemainAfterExit?

RemainAfterExit= Takes a boolean value that specifies whether the service shall be considered active even when all its processes exited. Defaults to no . GuessMainPID= Takes a boolean value that specifies whether systemd should try to guess the main PID of a service if it cannot be determined reliably.

What is ExecStop systemd?

The ExecStop setting is optional and is used to communicate with the service for a clean termination. The process specified by ExecStop will run in case the service crashes.


1 Answers

Use RemainAfterExit=yes for services, which somehow change state of the system. When you want that state reverted, you just stop the service. Then you can start it again, but not without first stopping it. An example would be service which creates a flag in filesystem to be used by some other application. On start, it create the flag file, then exists, but the service is kept as active by systemd. Then you can stop it and it will remove the flag file.

Use RemainAfterExit=no for services, which do some action, but do not change the state of the system. An example would be a service to cleanup /tmp. You start it, it will do its work and then be inactive (no need to stop it). And you can start it again anytime and will again to its work (cleanup).

like image 129
Marki555 Avatar answered Oct 03 '22 01:10

Marki555