简体   繁体   English

如何在启动时作为 raspberry pi 的(守护进程)服务执行 .NET Core 控制台应用程序

[英]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.我想知道如何在树莓派上将 dotnet 控制台应用程序作为服务运行。

I can start the application mannualy by typing '''./dotnet/garagedeur_pi/publish/Garagedeur'''我可以通过键入 '''./dotnet/garagedeur_pi/publish/Garageeur''' 手动启动应用程序

I've created a Garagedeur.Service file:我创建了一个 Garageeur.Service 文件:

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/.只需阅读错误消息,就会看到garagedeur/pi/ 与garagedeur_pi/ 不同。 Also there is a difference between Garagedeur.dll and Garagedeur – M. Spiller Feb 17 at 11:33 Garageeur.dll 和 Garageeur 之间也存在差异 – M. Spiller 2 月 17 日 11:33

You can look here how to create the service file Host ASP.NET on Linux with Nginx .您可以在此处查看如何使用 Nginx 在 Linux 上创建服务文件Host ASP.NET In your service file you have to add the location of .NET installation, like this:在您的服务文件中,您必须添加 .NET 安装的位置,如下所示:

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.路径/usr/bin/dotnet取决于您是否安装了 .NET。 On my raspberry pi this path is /home/pi/dotnet-arm32/dotnet .在我的树莓/home/pi/dotnet-arm32/dotnet这条路径是/home/pi/dotnet-arm32/dotnet You can finde the right path with the command您可以使用命令找到正确的路径

dotnet --info dotnet --info

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将.Net Core Console App部署到Raspberry PI和远程调试 - Deploy .Net Core Console App to Raspberry PI and Remote Debug 在Raspberry Pi上的.Net Core应用程序中忽略了Console.ReadLine - Console.ReadLine ignored in .Net Core app on Raspberry Pi Arch Linux启动应用程序(脚本)Raspberry Pi - Arch linux startup application (script) Raspberry Pi 如何在.NET Core Console应用程序中处理Scoped服务实例? - How is a Scoped service instance handled in a .NET Core Console application? 如何在 Raspberry PI 上运行 .net core 3.1 应用程序? - How to run .net core 3.1 app on Raspberry PI? 在.Net Core控制台应用程序中找不到依赖项-在启动时显示为丢失 - Dependencies not found in .Net Core console application - showing as missing on startup 自托管 .NET 核心控制台应用程序中的 Startup.cs - Startup.cs in a self-hosted .NET Core Console Application 带有 .Net Core 的 Raspberry Pi 3 上的串行端口 - Serial port on Raspberry Pi 3 with .Net Core Raspberry Pi上的.Net Core 2.1 GPIO filesystemwatcher - .Net Core 2.1 GPIO filesystemwatcher on Raspberry Pi 如何在我的 ASP.NET Core 应用程序中使用 Startup.cs 之外的服务? - How can I use a service outside of Startup.cs in my ASP.NET Core Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM