I have an ASP.NET Core web app on an Ubuntu VM that I'm trying to run on boot (following these docs). When I start my systemd service my app fails to run and I get this error:
kestrel-myapp.service: Changing to the requested working directory failed: No such file or directory
I'm a bit confused because I've verified that the path in the .service
file exists and I've changed the directory's owner to the www-data
user (I'm using nginx) with chmod 750
permissions.
Here's my .service file:
[Unit]
Description=MyApp Test
[Service]
User=www-data
WorkingDirectory=/var/www/myapp/Release/net8.0/publish/
ExecStart=/usr/bin/dotnet /var/www/myapp/Release/net8.0/publish/MyApp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_NOLOGO=true
# The default value is 90 seconds for most distributions.
TimeoutStopSec=90
[Install]
WantedBy=multi-user.target
Thanks for the help
I thought the original error in my question was what was causing my service to crash, but it turns out that the real issue was with another error and that it was my understanding of the logs that was the issue.
Running [journalctl -xu]
1 shows you ALL the logs for a specific unit from oldest to newest, so even when I updated the .service
file I kept seeing the old "no such directory" error, when in reality I unknowingly fixed it a while back it by changing the user and granting the appropriate permissions.