首页 > 解决方案 > 在 Ubuntu 上创建的红隼服务因错误而停止 (code=exited, status=200/CHDIR)

问题描述

我在 /etc/systemd/system 中创建了一个服务,如下所示:

$ cd /etc/systemd/system
$ sudo nano test.service

添加以下内容

[Unit]
Description=test app

[Service]
WorkingDirectory=/var/www/test-app
ExecStart=/usr/bin/dotnet /var/www/test-app/Test.App.dll
Restart=always
RestartSec=10
SyslogIdentifier=test
User=ubuntu
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

保存服务后运行以下命令

$ sudo systemctl enable test.service
$ sudo systemctl start test.service
$ sudo systemctl status test.service

但显示此错误

test.service - test app
   Loaded: loaded (/etc/systemd/system/test.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Sat 2020-02-15 10:41:19 UTC; 8s ago
  Process: 24631 ExecStart=/usr/bin/dotnet /var/www/test-app/Test.App.dll (code=exited, status=200/CHDIR)
 Main PID: 24631 (code=exited, status=200/CHDIR)

用户 (ubuntu) 存在并且拥有应用程序文件的适当所有权

标签: ubuntuasp.net-corekestrel

解决方案


我有同样的问题。我尝试了使用不同目录的权限、路径长度。但问题是工作目录路径中的一个小错误。已修复,一切正常。


推荐阅读