I have published a .NET 7 app on Ubuntu 22.04. The app is not starting up and I don't know how to begin to troubleshoot it. My systemd file starts the app then deactivates it shortly after.
What can I do next to discover the problem?
The .NET SDK is installed fine.
dotnet --info
.NET SDK:
Version: 7.0.105
Commit: e1bc5e001c
Runtime Environment:
OS Name: ubuntu
OS Version: 22.04
OS Platform: Linux
RID: ubuntu.22.04-x64
Base Path: /usr/lib/dotnet/sdk/7.0.105/
Host:
Version: 7.0.5
Architecture: x64
Commit: 8042d61b17
.NET SDKs installed:
7.0.105 [/usr/lib/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.5 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
DOTNET_ROOT [/usr/lib/dotnet]
global.json file:
Not found
Systemd service:
[Unit]
Description=My App
[Service]
Type=simple
WorkingDirectory=/var/myapp
Restart=on-failure
RestartSec=10
ExecStart=/usr/bin/dotnet /var/myapp/MyApp.dll
KillSignal=SIGINT
SyslogIdentifier=dotnet-project1
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Logs:
journalctl -f
Jun 14 01:20:16 localhost systemd[1]: Stopped myapp.service - My App.
Jun 14 01:20:16 localhost systemd[1]: Started myapp.service - My App.
Jun 14 01:20:16 localhost systemd[1]: myapp.service: Deactivated successfully.
sudo systemctl status myapp
myapp.service - My App
Loaded: loaded (/etc/systemd/system/myapp.service; enabled; preset: enabled)
Active: activating (auto-restart) since Wed 2023-06-14 01:29:49 UTC; 9s ago
Process: 58543 ExecStart=/usr/bin/dotnet /var/myapp/MyApp.dll (code=exited, status=0/SUCCESS)
Main PID: 58543 (code=exited, status=0/SUCCESS)
CPU: 880ms
Jun 14 01:29:49 localhost systemd[1]: myapp.service: Deactivated successfully.
When I go to the /var/myapp folder and run this command:
sudo dotnet MyApp.dll
I don't get any response.
How can I troubleshoot my app? There must be some logs somewhere that will tell me why it is failing? It worked fine on my personal computer before I published it.
Any help appreciated.
P.S.
These are more detailed logs from journalctl -f as the app is ran.
Jun 14 02:09:06 localhost sudo[61729]: myuser : TTY=pts/1 ; PWD=/home/myuser/MyApp/publish ; USER=root ; COMMAND=/usr/bin/dotnet MyApp.dll
Jun 14 02:09:06 localhost sudo[61729]: pam_unix(sudo:session): session opened for user root(uid=0) by myuser(uid=1000)
Jun 14 02:09:07 localhost sudo[61729]: pam_unix(sudo:session): session closed for user root
I had the same issue a few days ago.
What I imagine happened (at least in my case) is your app.config
(or other config file) has changed (mine was the database connection) and I had a single back slash in the DB Connection String which I copied, which is invalid JSON.
To prove this, copy your published config file and run it through any json validator and see the errors.
Another point of direction would be to remove serilog
(as a test) and you will see a bit more details confirming it's a config error.
(The reason it is not getting logged is, like you said, the error happens before Serilog
is completely setup. In their docs, they do mention a way to see more logs (see https://github.com/serilog/serilog/wiki/Debugging-and-Diagnostics) but it didnt help in my case)
EDIT
It doesnt have to be a config error for it not to show in serilog
. Any deep error which occurs before serilog
is set up, will not be displayed i.e. as mentioned in the comments, an Access Denied exception or similar. Sometimes, Console.Writeline
(or the default asp net core
logging which includes the console) is the way forward : )