systemd is the init system and service manager on most modern Linux distributions. See Linux for the systemctl and journalctl cheatsheet.
Example Unit File
/etc/systemd/system/myapp.service:
[Unit]
Description=My Go Service
After=network-online.target
Wants=network-online.target
StartLimitIntervalSec=60
StartLimitBurst=5
[Service]
User=myapp
Group=myapp
WorkingDirectory=/opt/myapp
ExecStart=/usr/local/bin/myapp
Restart=on-failure
RestartSec=2
NoNewPrivileges=true
ProtectSystem=strict
[Install]
WantedBy=multi-user.targetRun services as a dedicated unprivileged user (or
DynamicUser=yes), notroot. To disable restart rate-limiting completely, setStartLimitIntervalSec=0.
After editing:
sudo systemctl daemon-reload
sudo systemctl enable --now myapp.service
journalctl -fu myapp.service