如何向.Net Systemd服务添加环境变量?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何向.Net Systemd服务添加环境变量?相关的知识,希望对你有一定的参考价值。

我正在VM的Ubuntu 18中安装Worker Service。当我使用以下命令时出现错误

sudo systemctl start myservice.service

错误:

 ● myservice.service - dummyservice in .NET Loaded: loaded
 (/lib/systemd/system/myservice.service; disabled; vendor preset:
 enabled) Active: failed (Result: exit-code) since Tue 2020-05-26
 23:53:20 IST; 10min ago Process: 3634 ExecStart=/usr/bin/dotnet
 /home/linux/bin/Downloads/myservice.dll (code=exited,
 status=1/FAILURE)

 May 26 23:53:19 arvind systemd[1]: Starting myservice in .NET... May
 26 23:53:20 arvind dotnet[3634]: The user's home directory could not
 be determined. Set the 'DOTNET_CLI_HOME' environment variable to spec
 May 26 23:53:20 arvind systemd[1]: myservice.service: Control process
 exited, code=exited status=1 May 26 23:53:20 arvind systemd[1]:
 myservice.service: Failed with result 'exit-code'. May 26 23:53:20
 arvind systemd[1]: Failed to start myservice in .NET.

这是我的.service文件

[Unit]
Description=my Service in .NET
# Requires=xyz.service
# After=xyz.service

[Service]
Type=forking
ExecStart=/usr/bin/dotnet  /home/linux/Downloads/myService.dll

[Install]
WantedBy=multi-user.target

我该如何解决这个问题?

答案

我已将DOTNET_CLI_HOME添加到.service文件

Environment=DOTNET_CLI_HOME=/temp

现在该文件看起来像它

[Unit]
Description=my Service in .NET
# Requires=xyz.service
# After=xyz.service

[Service]
Type=forking
ExecStart=/usr/bin/dotnet  /home/linux/Downloads/myService.dll
Environment=DOTNET_CLI_HOME=/temp
[Install]
WantedBy=multi-user.target

以上是关于如何向.Net Systemd服务添加环境变量?的主要内容,如果未能解决你的问题,请参考以下文章

Systemd service文件中配置环境变量

Systemd service文件中配置环境变量

如何在 coreOS 上将 etcd 值添加到我的 systemd 服务中?

为什么ubuntu中的NET Core 3.1 BackgroundWorker无法访问环境变量?

harbor进程组件化运行及systemd 进程日志分写

如何在systemd中添加service