How to run golang web server forever on Linux


To run nodejs webserver forever, you can use forever like:

forever start index.js

How to do this with golang ?

There are many methods, i can show one of them:

Step 1:

vi /etc/systemd/system/my-go-daemon.service

content:

[Unit]
Description=My Go App

[Service]
Type=simple
WorkingDirectory=/home/go
ExecStart=/usr/local/go/bin/go run src/test1/main.go
Restart=always
 # Restart service after 10 seconds if golang service crashes
 RestartSec=10

[Install]
WantedBy=multi-user.target

Step 2:

systemctl enable my-go-daemon
systemctl start my-go-daemon

1 Comment

Leave a Reply