nano /etc/systemd/system/MyService.service
systemctl enable MyService.service
systemctl start MyService.service
systemctl stop MyService.service
systemctl status MyService.service
nano /etc/systemd/system/MyService.service
systemctl enable MyService.service
systemctl start MyService.service
systemctl stop MyService.service
systemctl status MyService.service
| [Unit] | |
| Description=MyService Description | |
| After=network.target | |
| [Service] | |
| WorkingDirectory=/path/to/app/ | |
| ExecStart=/usr/bin/dotnet /path/to/app/App.dll | |
| Restart=on-failure | |
| RestartSec=10 | |
| KillSignal=SIGINT | |
| SyslogIdentifier=log.antoniocampos | |
| User=www-data | |
| Group=www-data | |
| Environment=ASPNETCORE_ENVIRONMENT=Production | |
| EnvironmentFile=-/etc/myservice/env | |
| TimeoutStartSec=10 | |
| TimeoutStopSec=30 | |
| # Security | |
| ProtectSystem=full | |
| ProtectHome=true | |
| PrivateTmp=true | |
| NoNewPrivileges=true | |
| ProtectKernelModules=true | |
| ProtectKernelTunables=true | |
| ProtectControlGroups=true | |
| # Resources | |
| LimitNOFILE=65535 | |
| MemoryMax=512M | |
| # Logging | |
| StandardOutput=journal | |
| StandardError=journal | |
| [Install] | |
| WantedBy=multi-user.target |
IMPORTANT: The user set in User parameter MUST be in root group (must grant root access to the user): sudo usermod -a -G root www-data
I would advise strongly against is for the sake of security, we used systemd user service and no such root access was needed.
IMPORTANT: The user set in User parameter MUST be in root group (must grant root access to the user):
sudo usermod -a -G root www-data