Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go application run in production [closed]

Tags:

linux

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
like image 660
Yur Gasparyan Avatar asked Sep 15 '25 16:09

Yur Gasparyan


1 Answers

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.

like image 133
kichik Avatar answered Sep 18 '25 06:09

kichik