Create file at /lib/systemd/system/mygoservice.service
[Unit]
Description=mygoservice
ConditionPathExists=$GOPATH/src/mygoservice/mygoservice
After=network.target
[Service]
Type=simple
User=mygoservice
Group=mygoservice
LimitNOFILE=1024
Restart=on-failure
RestartSec=10
startLimitIntervalSec=60
WorkingDirectory=$GOPATH/src/mygoservice
ExecStart=$GOPATH/src/mygoservice/mygoservice --name=foo
# make sure log directory exists and owned by syslog
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p /var/log/mygoservice
ExecStartPre=/bin/chown syslog:adm /var/log/mygoservice
ExecStartPre=/bin/chmod 755 /var/log/mygoservice
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=mygoservice
[Install]
WantedBy=multi-user.target
Enable and start service
sudo systemctl enable mygoservice.service
sudo systemctl start mygoservice
# check status
sudo journalctl -f -u mygoservice