[Solved] Systemd service not working right

Hey everyone,

I'm trying to deploy an ASP .Net Core app to my webserver, but when I try running the app with a Systemd service, I get http 500 errors in the browser, however if I run the app manually, everything works as expected. When the service is started it tells me the app is running like it should and there are no errors. There is no indication that it isn't working right. The app should go to localhost:5000 and is then passed through a reverse proxy on Nginx to the internet. That part works fine. The service code is below, maybe there is an error in it?

[Unit]
Description=bazinga.tech-website

[Service]
ExecStart=/usr/bin/dotnet /home/bazinga-db/bazinga/CSharpWebsite.dll
Restart=always
RestartSec=10
SyslogIdentifier=bazinga-website
User=bazinga
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

I am using an example from Microsoft's site on deploying to a Linux server. The command I would use to run manually is:

dotnet CSharpWebsite.dll

Any idea why it may not work? I can provide some screenshots if requested. This is the first time I've used Systemd to start a program manually, so any help is appreciated.

bazinga = my name for obscurity

try this

sudo systemctl enable bazinga

Its enabled and running, I know how to do that, the output from Journalctl is exactly the same as if i were to run dotnet CSharpWebsite.dll, however it gives me HTTP 500 errors when run like this. I have no idea why. The logs aren't telling me anything.

The only thing I can maybe think of is that it needs a tty or something. There is output to the console when run a page is viewed.

Does this show you anything new?

sudo journalctl -u bazinga

Nope, nothing that running dotnet CSharpWebsite.dll doesn't already give me. Because of my reverse proxy with Nginx, I get HTTP 502 when nothing is running, and HTTP 500 when it is started as a service with Systemd.

could be a permissions issue

Anything useful in Nginx logs?

You are manually running the app as the bazinga user?

I'm doing both. Running dotnet CSharpWebsite.dll as bazinga works fine. I'm just looking again, and dotnet does issue some text to the terminal with the info 'tag' (not sure what to call it) which does show up when run manually, but not as a Systemd service.

Should also add that I am using this guide from Microsoft to write the service.

Here are some screenshots of the terminal output - note, this one has my name which is bazinga in the above text. I posted this to Reddit and Stackoverflow as well and didn't really want my name plastered all over the internet, but I trust this forum a lot more :P

Might be environment variables that exist in your login shell, but do not exist in systemd's environment.

Maybe, I am able to run the app as the user and root without issue. It seems to be all self contained, just a matter of running it.

The "content root path" differs under systemd. I'd concentrate on that.

Possibly setting "HOME=/home/stephenwiggins-db" in the systemd unit might help?

That's not it either. Its right. (sorry, haven't installed a fancy .bashrc profile yet)

I renamed the account. I made a mistake when creating the user accounts for Postgres.

I think my best best now is to test this on another system to see if something else is at play.

Edit: just tried it on a different VM with the same result. Both are Ubuntu 16.04. First is a Digital Ocean droplet, second is a full VM on a Proxmox machine.

Here is a screenshot of the actual service

Fixed it. Turns out I was missing a line in the service file for the WorkingDirectory. I must have deleted it when copying over the example.

1 Like