browse by category or date

Reviewing the logs of this website, is one of my weekly activities. Most of the time, I only need to clear the logs to save space. But today, I notice there’s something wrong with this post. The log indicates that NGINX is unable to reach the internal gateway (the Go application).

Well this is weird. I remember I already set the program as a background service. To ensure that this is the case, I checked if the service is already created in systemd:

sudo nano /lib/systemd/system/golisj.service

The file exists, and it has content:

[Unit]
Description=Golang Lisajeous Image Process Manager
Documentation=
Requires=nginx.service
After=nginx.service

[Service]
Type=simple
PIDFile=/run/golang/golisj.pid
ExecStart=-/root/go/src/server/server
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

Check Service Status

service golisj status

Output:

● golisj.service – Golang Lisajeous Image Process Manager
Loaded: loaded (/lib/systemd/system/golisj.service; disabled; vendor preset: enabled)
Active: inactive (dead)

Start Service

sudo service golisj start

Now we check the status

sudo service golisj status

Output:

Enable Service

To make sure the service is running after reboot, we need to enable the service

sudo systemctl enable golisj

Output:

Created symlink /etc/systemd/system/multi-user.target.wants/golisj.service → /lib/systemd/system/golisj.service.

Check the status again:

sudo service golisj status

Output:

To test it out, I rebooted the server. When I opened the post, I can see the animated gifs running. I Ctrl+F5 one more, the gifs is still there. That means the service is now running after restart.

I hope it helps. Cheers!

GD Star Rating
loading...
How To Run A Go Application As A Service In Ubuntu, 4.0 out of 5 based on 1 rating

Possibly relevant:

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Incoming Search

golang, linux, service, ubuntu

No Comment

Add Your Comment