Automate your OutagesIO Internet monitor on Linux

In this article, we’ll explain you how you can automate the startup of your OutagesIO Internet monitoring agent on your device using systemd.
Here we assume you already have an account on app.outagesio.com and have created your software agent.

You might opt to start and stop the agent manually or use something like rc.local to automatically start the agent when the system starts.
This article covers adding a service to automate the process.

First step

The first step is to log into your control panel at app.outagesio.com.
If you don’t yet have an account, simply create one here; https://app.outagesio.com/account/signUp
Once logged in, click on the Agents menu item.
Click on the ‘Create software agent’ option.
Pick the device platform which you need for your board or device.
Enter the local Internet providers business name.
Now enter the address where this agent is being installed. You can enter the whole address or part of it then click on ‘Click to auto fill address details’.
This should auto fill all of the details on the right hand side of the page.
If the map shows the correct location, you are done and can click on Create at the bottom of the page.
If the address is not right, try entering a nearby address then you can move the map around and click where the address is. Once you have the right location, click on Create.

At this point, follow the instructions and you’ll soon have an agent running on your device. Be sure to create the /etc/agentid or the program will not run.

Automating startup using systemd

If you want to automate starting the agent each time the device is rebooted, these are the steps to take.
This change will allow the systemd service to use the script to download the latest version and will prevent another instance of the agent from starting so that the system service will control it.

Next, let’s create a service for agent using your favorite editor.

# vi /etc/systemd/system/otm.service

Enter the following contents;

[Unit]
Description=Startup of the OutagesIO Internet monitor agent
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
ExecStart=/otm/starter.sh
WorkingDirectory=/otm
Restart=always
RestartSec=5
StandardError=syslog
SyslogIdentifier=%n

 

Note the directory being used above must be /otm/ and the user running the script must have network access.

Now that we have created the service, run the following command which will load the new file;
# systemctl daemon-reload

To have the agent auto start when your system starts, run the following;
# sudo systemctl enable otm.service

To start/stop the service or check the status, use the usual commands;
sudo systemctl xxx otm.service
xxx can equal enable, disable, start, stop ,status

You should now have a fully automated service.

Keep in mind than when you turn off your device, the agent service gets turned off as well which means it is no longer monitoring your Internet connection.  You will see that your agent shows Inactive in your OutagesIO dashboard. After 30 minutes or so, that status will change to Disconnected.

Finally, the status will change back to Active once your device is booted and running again.