Skip to content

Instantly share code, notes, and snippets.

@SpoonException
Forked from antoniocampos/MyService.service
Created July 31, 2022 15:57
Show Gist options
  • Select an option

  • Save SpoonException/32beecdd56649ec85cc9da0e6cc4af81 to your computer and use it in GitHub Desktop.

Select an option

Save SpoonException/32beecdd56649ec85cc9da0e6cc4af81 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