GoLang: Running a Go binary as a systemd service on Ubuntu 18.04 in 10 Minutes (without Docker)

Luci Bro
2 min readApr 4, 2021

The Go language with its simplicity, concurrency support, rich package ecosystem, and ability to compile down to a single binary is an attractive solution for writing services on Ubuntu.

When you want to deploy a dead-simple Go API and you don’t really have the urge to learn Docker and large scale deployment (although certainly a useful skill), you have come to the right tutorial.

We’re going to have a quick look at setting up running a golang web app on a Linux VPS without spending more than 10 minutes on it.

First Test your app

Let’a assume our goapp is install directory /home/lucian/myapp

First test your app by running it manually

go run .

Create System Service file

Create a new file as root user vim /etc/systemd/system/appgo.service and paste below code

[Unit]
Description=MyApp Go Service
ConditionPathExists=/home/lucian/myapp
After=network.target
[Service]
Type=simple
User=burn
Group=burn
WorkingDirectory=/home/lucian/myapp
ExecStart=/usr/local/go/bin/go run .
Restart=on-failure
RestartSec=10

--

--

No responses yet