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

Recent search terms:

  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1831 HBjDhyemy18AqbATokpIWQ7db-PYEeL-6CaP2lU8iPyT36pSrwGEWTGMK9LTvuJm f278683ab6fc749e206ac540b95a441ab6a5ded6&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme

Leave a Reply