Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core 3.0 on Linux, systemd service start a independent process

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?

like image 319
S.Zarges Avatar asked Nov 29 '19 12:11

S.Zarges


People also ask

Can I run dotnet application on Linux?

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.


1 Answers

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 to process, only the main process itself is killed. If set to mixed, 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 to none, 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.

like image 80
jcb Avatar answered Nov 06 '22 12:11

jcb