I've a .Net Core 3.0 application which runs as systemd service on my Raspberry Pi (Raspbian).
Now I have a second application which updates the service application to a new version.
The service application is detecting that there is a new update available and starts the update application with the following command.
Process.Start("/bin/bash", "-c \"nohup /./test/update/bin/start-update\" >/dev/null 2>&1 &");
The update application stops the service application and this also kills the started update application.
When I run the command from the console everything works fine.
Has anyone a solution to start a new complete independent process from a systemd service which is written in C#/.Net Core 3.0?
NET is available in the official package archives for various Linux distributions, including the following ones. . NET may or may not be supported by Microsoft as published in the official package archives. You can still open issues at dotnet/core if you run into problems.
I'm currently in the same boat, only with a service based on a Java application (that starts an update process that needs to restart the service, thereby indirectly killing itself).
The default behaviour of SystemD is to stop (kill) all processes in the same ControlGroup as the service. This can be changed with the KillMode=
directive, described here:
Specifies how processes of this unit shall be killed. One of
control-group
,process
,mixed
,none
.If set to
control-group
, all remaining processes in the control group of this unit will be killed on unit stop (for services: after the stop command is executed, as configured with ExecStop=). If set toprocess
, only the main process itself is killed. If set tomixed
, the SIGTERM signal (see below) is sent to the main process while the subsequent SIGKILL signal (see below) is sent to all remaining processes of the unit's control group. If set tonone
, no process is killed. In this case, only the stop command will be executed on unit stop, but no process will be killed otherwise. Processes remaining alive after stop are left in their control group and the control group continues to exist after stop unless it is empty.[...]
Defaults to
control-group
.
You might want to switch from control-group
(the default) to either process
, which will only kill your main process, or none
and provide a StopExec=
directive that details how to stop your service.
In my case there are some more processes that get started by my main start script, so either option would result in some leftover processes, but for you this might be the way to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With