Running a Go binary as a systemd service on Ubuntu 16.04

This is a quick guide to run a go binary as a systemd service (daemon) on Ubuntu 16.04, which is the latest LTS version available.

This article will not talk about how to create golang services, cloud architecture, etc.

Creating gatomocho as systemd service

Create /lib/systemd/system/gatomocho.service with the content:

The absolute paths in ConditionPathExistsWorkingDirectory and ExecStart all need to be modified per your environment. Notice that we have instructed systemd to run the process as the user gatomocho, so we need to create that user as well:

The journal is stored as a binary file, so it cannot be tailed directly. But if we configure syslog, we have syslog forwarding enabled so that we can have our log sent to /var/log/gatomocho/.

What’s next?

The answer depends on how you configured your env. Few bullets to take care of:

  • Update firewall rules
  • Create a domain server on nginx
  • Enable SSL for your domain