How to restart a systemctl service from within the process
Karl Auer
kauer at biplane.com.au
Sun Nov 22 11:04:11 UTC 2020
On Sun, 2020-11-22 at 09:45 +0000, Colin Law wrote:
> I have a service (a nodejs process running node-red) and want it to
> self-restart. The obvious way appears to be to invoke
> systemctl restart theservice
> but I am concerned about the fact that the process running the
> systemctl command will itself be killed as part of the restart. It
> does seem to work but that is not a guarantee that there is not a
> possible race condition that could cause it to fail. I am hoping
> that
> someone can reassure me that there is not actually a problem doing
> this.
>
> Colin
>
Not 100% sure what they are off the top of my head ("Restart=on-
failure" from memory), but there are options you can put in the
.service file that will cause systemd to restart the service if it
exits, along with options to prevent runaway restarts, control how long
before it restarts and so on. There's also an option to just let it die
if it restarts too often within a given period (StartLimitBurst?).ll
That would be my suggestion. You'd probably find the answer in "man
systemd" or related.
Regards, K.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer
GPG fingerprint: 2561 E9EC D868 E73C 8AF1 49CF EE50 4B1D CCA1 5170
Old fingerprint: 8D08 9CAA 649A AFEF E862 062A 2E97 42D4 A2A0 616D
More information about the ubuntu-users
mailing list