Adding a Linux Service
Creating Service
Open a new service file in a text editor.
sudo nano /etc/systemd/system/candle.service
Sample contents of the file:
[Unit]
Description=Candle Test / Demo Server Built from Develop Branch
[Service]
WorkingDirectory=/var/aspnetcore/candle.cloud
ExecStart=/var/aspnetcore/candle.cloud/Candle.WebApp --listen-url=http://192.168.0.24:5000
Restart=always
RestartSec=10 # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=candle-cloud
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Save the file and then enable the services.
sudo systemctl enable candle.service
Start the service and verify that it's running:
sudo systemctl start candle.service
sudo systemctl status candle.service
Viewing logs
Since the web app using Kestrel is managed using `systemd`, all events and processes are logged to a centralized journal. However, this journal includes all entries for all services and processes managed by `systemd`. To view the `candle.service`-specific items, use the following command:
sudo journalctl -fu candle.service
For further filtering, time options such as `--since today`, `--until 1 hour ago` or a combination of these can reduce the amount of entries returned.
sudo journalctl -fu candle.service --since "2018-5-18" --until "2018-5-30 04:00"