简体   繁体   中英

Application does not exit when an error happening on systemd

So I developed an application using .net-core , I run this software on a linux machine as a daemon service using systemd . Now the problem is that when an error happen in the app, it enters in a "limbo", infact each activity of the application is logged using Console.WriteLine and I can see this log typing that command on linux machine: journalctl -fu app.service .

When the error happen the log doesn't write anything, but at the same time the application keep running and this is really strange because I setup the service with the following configuration:

[Unit]
Description = Daemon service

[Service]
ExecStart = /usr/bin/dotnet /home/my username/Desktop/publish/SimpleApp.dll
WorkingDirectory= /home/foo/Desktop/publish
Restart = always
RestartSec = 3

[Install]
WantedBy = multi-user.target

as you can see the Restart = always should restart the app when an error is raised. When an exception is raised the method Error() write the error inside a file and then kill the software in the following way:

public void Error(Exception ex)
{
   File.WriteAllText("error.txt", ex.ToString());
   Environment.Exit(1); 
}

Must be some problem on Environment.Exit with the Linux environment, or I did something wrong calling Environment.Exit . There are other ways to close an application like this which run as system service?

Thanks

Try the following:

public void Error(Exception ex)
{
   File.WriteAllText("error.txt", ex.ToString());
   throw new Exception ("This is a test to see if restart is working");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM