Reputation: 306
I'm trying to run my asp .net core app as a service under Ubuntu 16.04. I've created service configuration following this documentation
[Unit]
Description=TNW Main Service
[Service]
WorkingDirectory=/home/tnw
ExecStart=/usr/bin/dotnet /home/tnw/Tnw.MealsApi.dll
Restart=always
RestartSec=10
SyslogIdentifier=tnw
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
I've enabled my service:
sudo systemctl enable tnw.service
And finally I've tried to run it but I obtain exception:
● tnw.service - TNW Main Service Loaded: loaded (/etc/systemd/system/tnw.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: core-dump) since Tue 2019-09-10 12:57:20 CEST; 118ms ago
Process: 15160 ExecStart=/usr/bin/dotnet /home/tnw/Tnw.MealsApi.dll (code=dumped, signal=ABRT)
Main PID: 15160 (code=dumped, signal=ABRT)
Sep 10 12:57:20 server767126 systemd[1]: tnw.service: Unit entered failed state.
Sep 10 12:57:20 server767126 systemd[1]: tnw.service: Failed with result 'core-dump'.
When I run this app manually it works fine.
sudo dotnet Tnw.MealsApi.dll
//Edit I've found in journal following exception:
System.Net.Sockets.SocketException (13): Permission denied
Upvotes: 8
Views: 15594
Reputation: 1
my service is running fine but not able to access outside as it is showing 502 , if I am running with direct command then it is working fine. need help on this fix
below is service status .
Demo.service - Demo
Loaded: loaded (/etc/systemd/system/Demo.service; enabled; preset: disabled)
Active: active (running) since Tue 2023-07-11 12:29:39 UTC; 6s ago
Main PID: 1476925 (dotnet)
Tasks: 15 (limit: 4568)
Memory: 15.6M
CPU: 389ms
CGroup: /system.slice/Demo.service
└─1476925 /usr/bin/dotnet /home/ec2-user/wwwroot/WebApp.dll --urls http://localhost:5000
Upvotes: 0
Reputation: 1583
In my case, the reason was an exception on the program startup. I've found it using this command: journalctl -f
.
Also, it's recommended to wrap a program startup with try
block and log the error to file using Serilog for example.
Upvotes: 4
Reputation: 17432
As per this use Downloads
folder to keep your dll
. Below configuration of .service
file
[Unit]
Description=MyService in .NET
# Requires=xyz.service
# After=xyz.service
[Service]
Type=simple
ExecStart=/usr/bin/dotnet /home/linux/Downloads/MyService.dll
[Install]
WantedBy=multi-user.target
This path /home/linux/Downloads/MyService.dll
can be different in your case.
And then run
sudo systemctl daemon-reload
Upvotes: 1