【问题标题】:Cannot execute dotnet app as daemon service无法将 dotnet 应用程序作为守护程序服务执行
【发布时间】:2018-05-22 09:52:35
【问题描述】:

我正在尝试将我的 dotnet 应用程序作为守护程序服务运行,我所做的第一步是:

  1. 使用NetCore 2.0 创建了应用程序
  2. 使用dotnet publish bot 构建二进制文件

Ubuntu 终端内我创建了一个用户来运行守护进程:

sudo useradd -s /sbin/nologin dotnetuser
sudo mkdir /var/bot
sudo cp -R /home/publish/* /var/bot
sudo chown -R dotnetuser:dotnetuser /var/bot

所以我在/etc/systemd/system/netcore-console-bot.service目录下创建了一个自定义systemd单元文件:

[Unit]
Description= Bot console application
DefaultDependencies = no

[Service]
Type = oneshot
RemainAfterExit = no
ExecStart= /var/bot/ bot.dll
WorkingDirectory = /var/bot
User = dotnetuser
Group = dotnetuser

[install]

我尝试使用systemctl status 命令执行daemonstart netcore-console-bot.service

但我得到了:

netcoreconsole-bot.service:主进程退出,code=exit

我做错了什么?

【问题讨论】:

  • where发布并定位到哪个操作系统?此错误抱怨二进制文件本身。如果您为 Windows 编译并尝试在 Linux 上运行,或者为 x64 编译并尝试在 x86 上运行,您会收到此错误
  • 错误表明您正在尝试启动服务而不启动CLR
  • 可以直接用dotnet path/to/the.dll运行可执行文件吗?
  • 可能是因为您的 ExecStart 部分中有不必要的空间?

标签: c# .net linux daemon


【解决方案1】:

我很确定您需要从我的测试中做出的唯一更改是确保告诉 dotnet 运行 dll。我的路径应该非常接近您需要做的事情。或者,您可以在发布运行时并将运行时与应用程序打包时使用self-contained deployment

[Unit]
Description= Bot console application
DefaultDependencies = no

[Service]
Type = oneshot
RemainAfterExit = no
ExecStart= /usr/bin/dotnet /var/bot/bot.dll
WorkingDirectory = /var/bot
User = dotnetuser
Group = dotnetuser

[install]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 2010-09-06
    • 1970-01-01
    • 2017-01-31
    • 2011-02-15
    • 2019-06-01
    • 1970-01-01
    相关资源
    最近更新 更多