简体   繁体   中英

How to execute a .NET Core console application on startup as a (daemon) service for the raspberry pi

I would like to know how i can run a dotnet console application as a service on a raspberry pi.

I can start the application mannualy by typing '''./dotnet/garagedeur_pi/publish/Garagedeur'''

I've created a Garagedeur.Service file:

Description=Garagedeur

[Service]
ExecStart=/home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll
WorkingDirectory=/home/pi/dotnet/garagedeur/pi/publish
#Restart=always
#RestartSec=10
User=pi

[Install]
WantedBy=multi-user.target

When I check the status I get this:

● Garagedeur.service - Garagedeur
   Loaded: loaded (/lib/systemd/system/Garagedeur.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2020-02-17 12:09:49 CET; 11min ago
  Process: 1142 ExecStart=/home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll (code=exited, status=200/CHDIR)
 Main PID: 1142 (code=exited, status=200/CHDIR)

Feb 17 12:09:49 raspberrypi systemd[1]: Started Garagedeur.
Feb 17 12:09:49 raspberrypi systemd[1142]: Garagedeur.service: Changing to the requested working directory failed: No such file or directory
Feb 17 12:09:49 raspberrypi systemd[1142]: Garagedeur.service: Failed at step CHDIR spawning /home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll: No such file or directory
Feb 17 12:09:49 raspberrypi systemd[1]: Garagedeur.service: Main process exited, code=exited, status=200/CHDIR
Feb 17 12:09:49 raspberrypi systemd[1]: Garagedeur.service: Failed with result 'exit-code'.

Any help is greatly appreciated.

Solution:

Just read the error message and see that garagedeur/pi/ is different from garagedeur_pi/. Also there is a difference between Garagedeur.dll and Garagedeur – M. Spiller Feb 17 at 11:33

You can look here how to create the service file Host ASP.NET on Linux with Nginx . In your service file you have to add the location of .NET installation, like this:

ExecStart=/usr/bin/dotnet /home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll

Here a example:

[Unit]
Description=Garagedeur

[Service]
ExecStart=/usr/bin/dotnet /home/pi/dotnet/garagedeur_pi/publish/Garagedeur.dll
WorkingDirectory=/home/pi/dotnet/garagedeur/pi/publish
Restart=always
RestartSec=10
User=pi

[Install]
WantedBy=multi-user.target

The path /usr/bin/dotnet is depending were you have installed .NET. On my raspberry pi this path is /home/pi/dotnet-arm32/dotnet . You can finde the right path with the command

dotnet --info

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