Skip to content

Instantly share code, notes, and snippets.

@mangowi
Forked from antoniocampos/MyService.service
Created August 14, 2022 12:49
Show Gist options
  • Save mangowi/8d32f9af7ff4c311bed542c97ee0b525 to your computer and use it in GitHub Desktop.
Save mangowi/8d32f9af7ff4c311bed542c97ee0b525 to your computer and use it in GitHub Desktop.
.net Core Systemd Service Example (Linux autostart you .net app)

First edit/create your .service file, with your favorite editor

use the example below...

nano /etc/systemd/system/MyService.service

Enable your service on boot

systemctl enable MyService.service

Start your service??

systemctl start MyService.service

Stop the service?

systemctl stop MyService.service

Want to know the service status??

systemctl status MyService.service

[Unit]
Description=MyService Description
[Service]
WorkingDirectory=/path/to/app/
ExecStart=/usr/bin/dotnet /path/to/app/App.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=log.antoniocampos
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
TimeoutStopSec=30
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment