[Linux Server] Configuring applications to run at startup
by Riley MacDonald, July 21, 2018

I run a headless Ubuntu Server (16.04.4 LTS) which supports many personal functions. To configure applications to run at boot/startup I use systemd. Unfortunately the process is not always straight forward. This blog post demonstrates how I added the no-ip DUP (dynamic update client) to run as a system service at boot/startup.

Create a new service
Services are located at /lib/systemd/system. To start I created a new service:

$ cd /lib/systemd/system
$ sudo touch noip.service
$ sudo vim noip.service

Start by defining some basic Unit data. I defined a description and indicated this service should run after the network.target service has been loaded.

1
2
3
[Unit]
Description=NoIP
After=syslog.target network.target

Now define the system data indicating instructions for start/restart.

1
2
3
4
5
[Service]
Type=forking
Restart=on-failure
RestartSec=20 5
ExecStart=/usr/local/bin/noip2 -c /usr/local/etc/no-ip2.conf

I needed to add Type=forking in order to get this working. From systemd.service docs:

Note that systemd assumes here that the process started by systemd will continue running until the service terminates. If the program daemonizes itself (i.e. forks), please use Type=forking instead.

The WantedBy instruction allows you to specify a dependency relationship similar to what the Wants instruction does in the [Unit] section. I’m pretty sure I need multiple users for this case.

1
2
[Install]
WantedBy=multi-user.target

The entire noip.service file should now look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=NoIP
After=syslog.target network.target
 
[Service]
Type=forking
Restart=on-failure
RestartSec=20 5
ExecStart=/usr/local/bin/noip2 -c /usr/local/etc/no-ip2.conf
 
[Install]
WantedBy = multi-user.target

Enable the new service
To enable the service register it with systemctl by running:

/lib/systemd/system $ sudo systemctl enable noip.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/noip.service to /lib/systemd/system/noip.service.

Notice a symlink has been created for the new service.

Start and verify the new service
Now the service can be started (and will be started automatically at boot). Verify it’s able to start and stop using the start, stop and status arguments.

$ sudo systemctl start noip.service
$ sudo systemctl status noip.service
● noip.service - NoIP
   Loaded: loaded (/lib/systemd/system/noip.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-07-21 12:26:03 ADT; 4s ago
  Process: 25720 ExecStart=/usr/local/bin/noip2 -c /usr/local/etc/no-ip2.conf (code=exited, status=0/SUCCESS)
 Main PID: 25723 (noip2)
    Tasks: 1
   Memory: 168.0K
      CPU: 14ms
   CGroup: /system.slice/noip.service
           └─25723 /usr/local/bin/noip2 -c /usr/local/etc/no-ip2.conf
 
Jul 21 12:26:03 bridget systemd[1]: Starting NoIP...
Jul 21 12:26:03 bridget noip2[25723]: v2.1.9 daemon started with NAT enabled
Jul 21 12:26:03 bridget systemd[1]: Started NoIP.

Success
The no-ip DUP client is now enabled and will run at startup. Now any changes to my IP address will be reported to no-ip and my hosts will automatically be updated.

NOIP and Passwords
Keep in mind: if you reset your noip password you’ll also need to update your noip configuration file otherwise the client will silently fail.

Open the comment form

Leave a comment:

Comments will be reviewed before they are posted.

User Comments:

[Python] How to write and host a chatbot for slack - Riley MacDonald on 2018-08-27 02:35:46 said:
[…] you can simply checkout the code on the server and install it as a systemd process. See my post on [Linux Server] Configuring applications to run at startup for more detailed instructions on this. It’s important to to use virtualenv python […]