How to add environment variable 'DOTNET_CLI_HOME' to .Net Systemd service?

Viewed 4811

I am installing Worker Service in VM's Ubuntu 18. When I am using below command getting error

sudo systemctl start myservice.service

Error:

 ● 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.

This is my .service file

[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

How can I solve this issue?

1 Answers

I have added DOTNET_CLI_HOME to .service file

Environment=DOTNET_CLI_HOME=/temp

Now that file looks like it

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

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