Tuesday, August 18, 2015

Creating an Ookla Netgauge systemd Startup Service on Linux


##########

UPDATE - 9/8/2017
If using the newer ooklaserver.sh installer (instead of netgauge_ooklaserver_install.sh), then make sure your ookla.service file has the following in the proper place.

[Service]
ExecStart=/usr/local/ookla/ooklaserver.sh start
ExecStop=/usr/local/ookla/ooklaserver.sh stop
PIDFile=/root/ookla/OoklaServer.pid

You can find out more about using the newer installer here:
https://support.ookla.com/hc/en-us/articles/234578528

#########


I recently installed Ookla's Netgauge product on CentOS 7, only to find out that the install doesn't create a systemd service and therefore the Ookla server daemon won't start at boot either.

Here are the easy steps you can take to fix the issue:

cd into your install directory. For me this is /usr/local/ookla

cd /usr/local/ookla
Now we need to change a few things within the netgauge_ooklaserver_install.sh script that is also used to start, stop and restart the daemon. Obviously, you can use your favorite editor; I'll stick with vi.

vi netgauge_ooklaserver_install.sh
At the top of the file, underneath the existing variables, add this one with the path to the install dir. (Note, there's already an INSTALL_DIR variable. If you'd like to just use that, rather than create a completely new one, then that's up to you. Just keep in mind that you'll need to use $INSTALL_DIR instead of $DIR_FULL, for the rest of these steps)

DIR_FULL="/usr/local/ookla"
Find the 'goto_speedtest_folder()' section and comment out the 'dir_full=`pwd`' variable, since we've already declared it up above. You will also need to find and replace $dir_full with $DIR_FULL on the next line.

goto_speedtest_folder() {
# determine if base install folder exists
#dir_full=`pwd`
dir_base=`basename $DIR_FULL`

Find the 'stop_if_running()' and 'start_if_not_running()' sections and add $DIR_FULL/ in front of every place that $PID_FILE exists. There should only be two in each section.

stop_if_running() {
if [ -f "$DIR_FULL/$PID_FILE" ]; then
daemon_pid=`cat $DIR_FULL/$PID_FILE`

start_if_not_running() {
if [ -f "$DIR_FULL/$PID_FILE" ]; then
daemon_pid=`cat $DIR_FULL/$PID_FILE`

Find the 'start()' section and add $DIR_FULL/ in front of every place that $PID_FILE and $DAEMON_FILE exists. There should be seven places where this needs changed. The only time you shouldn't be doing this is where the variable is part of a printf command. Also comment out the existing $dir_full=`pwd` line as we did above.

The additions will look like this after you're done:

"$DIR_FULL/$PID_FILE"
"$DIR_FULL/$DAEMON_FILE"
However, you won't be changing lines that start like this:

printf "Starting $DAEMON_FILE"
Now save the file.

Next we'll need to create the ookla service. cd to the /usr/lib/systemd/system directory and create the file.

cd /usr/lib/systemd/system
vi ookla.service

Now put this code into the file:

[Unit]
Description="OoklaServer"

[Service]
ExecStart=/usr/local/ookla/netgauge_ooklaserver_install.sh start
ExecStop=/usr/local/ookla/netgauge_ooklaserver_install.sh stop
PIDFile=/usr/local/ookla/OoklaServer.pid

[Install]
WantedBy=multi-user.target

Save the file and restart the systemd daemon.
systemd daemon-reload
To start the service at boot, type:

systemctl enable ookla
Now try to start the service.

systemctl start ookla
Now query the status of the ookla service:

systemctl status ookla
You should see something similar to the following. Notice that the 'Loaded' line says 'enabled', meaning that it is set to start on boot and ensure that it is running and active.

ookla.service - "OoklaServer"
Loaded: loaded (/usr/lib/systemd/system/ookla.service; enabled)
Active: active (running) since Tue 2015-08-18 14:39:22 EDT; 4s ago
Process: 4069 ExecStop=/usr/local/ookla/netgauge_ooklaserver_install.sh stop (code=exited, status=0/SUCCESS)
Main PID: 4123 (OoklaServer)
CGroup: /system.slice/ookla.service
ΓΆΓΆ4123 ./usr/local/ookla/OoklaServer --daemon --pidfile=/usr/local/ookla/OoklaServer.pid

Aug 18 14:39:22 localhost systemd[1]: Starting "OoklaServer"...
Aug 18 14:39:22 localhost systemd[1]: Started "OoklaServer".
Aug 18 14:39:23 localhost netgauge_ooklaserver_install.sh[4120]: Starting OoklaServer
Aug 18 14:39:23 localhost netgauge_ooklaserver_install.sh[4120]: Daemon Started (4123)

No comments:

Post a Comment