I create a service in /etc/systemd/system as follow :
$ cd /etc/systemd/system
$ sudo nano test.service
Add the following content
[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
after save the service run following commands
$ sudo systemctl enable test.service
$ sudo systemctl start test.service
$ sudo systemctl status test.service
but display this error
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)
The user (ubuntu) is exist and have proper ownership of the app's files