I have a production server with ssh root access. There I have installed go and have cloned my project, I am working with putty to run my application but after closing putty my go application stops working, what I need to do to get always running go application?
Here is my go.service file
[Unit]
Description=my amazing service
[Service]
Restart=always
RestartSec=3
ExecStart=go run /root/work/src/main/main.go
[Install]
WantedBy=multi-user.target
For recent versions of Ubuntu create /etc/systemd/system/myservice.service
with:
[Unit]
Description=my amazing service
[Service]
Restart=always
RestartSec=3
ExecStart=/usr/bin/path/to/my/service some args
[Install]
WantedBy=multi-user.target
Run this one time:
systemctl enable myservice
You can then start and stop your service with:
sudo systemctl start myservice
sudo systemctl stop myservice
It will also start automatically when the server boots, and restart if it crashes.
More here:
https://wiki.ubuntu.com/SystemdForUpstartUsers#Example_Systemd_service
There are many other service management solutions, but systemd comes with Ubuntu 16 so it's probably the easiest to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With