You need your API to run as a service to survive the reboot.
sudo nano /etc/systemd/system/fanks-api.service
[Unit]
Description=Fanks Api
[Service]
WorkingDirectory=/var/apps/fanks-api
ExecStart=/var/apps/fanks-api/Fanks.Api
Restart=always
RestartSec=10
KillSignal=SIGINT
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
StandardOutput=append:/var/log/fanks-api.log
StandardError=/var/log/fanks-api.log
[Install]
WantedBy=multi-user.target
The log file we specified above need to be created manually:
sudo touch /var/log/fanks-api.log
We also need to give www-data
user permission to write to it:
sudo chown www-data:www-data /var/log/fanks-api.log
Let's spin the service:
sudo systemctl enable fanks-api.service
sudo systemctl start fanks-api
sudo systemctl status fanks-api
You should see this:
● fanks-api.service - Fanks Api
Loaded: loaded (/etc/systemd/system/fanks-api.service; enabled; preset: enabled)
Active: active (running) since Fri 2025-06-06 17:19:33 UTC; 3s ago
Main PID: 18113 (Fanks.Api)
Tasks: 15 (limit: 995)
Memory: 40.1M (peak: 40.2M)
CPU: 1.015s
CGroup: /system.slice/fanks-api.service
└─18113 /var/apps/fanks-api/Fanks.Api
Verify:
curl http://localhost:5000
Hello there! I'm Obi-Wan Kenobi, and this is the API you're looking for.
If you need to view logs just hit:
tail /var/log/fanks-api.log