Skip to content

The httpcats.systemd.service File

Filename Location Group Project/Repository
httpcats.systemd.service ./files/httpcats.systemd.service configuration ansible

Why?

With our binary present on the remote servers we need to set up a service that runs that binary so that we can serve our static images. We'll use systemd as it's what ships with most Linux distributions in this day and age.

All we have to do is upload a pre-configured systemd configuration file which tells systemd how our service is to be executed and managed.

Breakdown

First we configure this "unit":

1
2
3
[Unit]
Description=HTTP DevOps Cats
After=network.target auditd.service

We're supplying a description for our service so that it's clear what it is when it's displayed in the output of various systemd tools, like systemctl. The After property determines WHEN the service is started. We need to start after the networking and auditing stacks have started.

Next we configure the service itself:

1
2
3
4
5
[Service]
ExecStart=/home/ubuntu/httpcats/httpcats
WorkingDirectory=/home/ubuntu/httpcats/
RuntimeDirectory=/home/ubuntu/httpcats/
RuntimeDirectoryMode=0755

Most of the properties we're configuring here are obvious: what to run and where to run it.

Finally we tell systemd how-to "install" the service into its database:

1
2
[Install]
Alias=httpcats.service

The Solution

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[Unit]
Description=HTTP DevOps Cats
After=network.target auditd.service

[Service]
ExecStart=/home/ubuntu/httpcats/httpcats
WorkingDirectory=/home/ubuntu/httpcats/
RuntimeDirectory=/home/ubuntu/httpcats/
RuntimeDirectoryMode=0755

[Install]
Alias=httpcats.service

Committing the Code

  1. Set your working directory to the configuration/ansible repository
  2. Save the file as httpcats.systemd.service and use git add httpcats.systemd.service to add it to the Git staging area
  3. Use git commit -am 'ensuring we can manage our app via systemd' to commit the file to our repository
  4. Push the code to GitLab.com: git push