8

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
BąQ
  • 296
  • 1
  • 3
  • 13
  • Hi, did you find a solution for this? – Vindberg Sep 18 '19 at 04:57
  • Hi, in my case problem is connected with fact that user wwwdata has no privileges to use port 80 and 443 so as workaround I've used root user. But it is only temporary solution. I've tried many tutorials how to add privileges to other user but without success. – BąQ Sep 18 '19 at 05:04
  • 1
    Have you tried changing to a non-priviledges port number eg. 5000 and then add a redirect in iptables like this: sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 5000 – Vindberg Sep 18 '19 at 07:05
  • I'll try but I'm sure if it will be work with. net core automatic redirect. Thanks! – BąQ Sep 18 '19 at 17:47
  • I see this thread is a bit old, but I wanted to ask if some of you guys have found the solution to this issue. In my case, I'm hosting a net core API and a SignalR service both in the same container. API is redirecting from port 5000(HTTP), 5001(HTTPS). SignarR Service from the port 5002(HTTP), 5003(HTTPS). Exactly as the original post, when I run manually the dll it works, but the service is not able to start the process, I guess due to the lack of permissions to port 5002, 5003. Thanks. – Sergio Hernández Jan 11 '21 at 06:04

3 Answers3

2

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.

Rodion Mostovoi
  • 1,205
  • 12
  • 16
1

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
R15
  • 13,982
  • 14
  • 97
  • 173
0

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

Zameer
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 15 '23 at 02:03