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)

Tuesday, December 16, 2014

CentOS 7 Teaming with VLANS


I'm not a Linux guru, but I wanted to share my experience (aka trouble) with implementing Linux Teaming for the first time. I'll also throw in some VLAN configuration on top of it.

After a quick Google search, I started off here. Seemed easy enough. Just like bonding (which I've done before), with some different statements in the ifcfg files.

Trouble was, it wasn't coming up correctly. The physical interfaces weren't being added to the team. After hours of troubleshooting, I decided to remove the line 'TYPE=ETHERNET' in the ifcfg-em1 and em2 files. Apparently it was conflicting with the 'DEVICETYPE=TeamPort' line; because after the change, the team and it's ports came up as expected!

Here are some quick config steps.

First, let's install teamd.

yum install teamd
Second, I'm not a big fan of NetworkManager, so let's remove it (or just disable if you'd like).

yum remove NetworkManager
OR

systemctl stop NetworkManager.service
systemctl disable NetworkManager.service

The VLAN module should be loaded by default, but you can double-check with the following command.

modprobe --first-time 8021q
And you should get this output:

modprobe: ERROR: could not insert '8021q': Module already in kernel
Now let's configure the main team interface. In our overall config, each vlan will have it's own IP address, so we don't configure any IP addresses on this interface. Obviously replace 'lacp' with whatever load-sharing/redundancy method you'll be using. Some people like to add "link_watch":{"name":"ethtool"} to the config as well; but that is the default, so we'll leave it out. Since we're doing lacp, ethtool is our only linkwatcher option anyway.

cd /etc/sysconfig/network-scripts
vi ifcfg-team0

DEVICE=team0
DEVICETYPE=Team
TEAM_CONFIG='{"runner":{"name":"lacp"}}'
ONBOOT=yes
BOOTPROTO=none

Let's configure each of the physical interfaces that will be used in the team. Remember, this is where we need to remove any line that says 'TYPE=ETHERNET'. The 'ONBOOT' parameter can be 'no'; as the main team0 interface will bring these ports up automatically.

vi ifcfg-interface

DEVICETYPE=TeamPort
TEAM_MASTER=team0
BOOTPROTO=none
ONBOOT=no

Now let's get each of the VLAN interfaces configured.

vi ifcfg-team0.vlan-id

DEVICE=team0.vlan-id
IPADDR=ip-address
NETMASK=subnet-mask
ONBOOT=static
VLAN=yes

Finally, restart the network. If this command throws an error, then just do a server reboot.

systemctl restart network
After networking is restarted, you can verify that the ports were successfully added to the team by using either of these commands:

teamnl team0 ports
teamdctl team0 state view