Table of Contents: Linux

Most Popular: Linux

Ubuntu Server – Apache 2.4 Upgrade Changes

As many of you may have noticed, upgrading to Apache 2.4 can either cause the “apache2” service to fail to start altogether or may render your websites more or less inoperable. Luckily, there are only a few minor changes to look for that will hopefully get you back up and running with a minimal period of downtime.

  1. During the upgrade, if you decided to keep your original versions of your config files like I did (always a good idea), you will then end up with some extra files with “.dpkg-dist” on the end of the filename. These are the latest version of the config files. As a best practice with any major config file changes, I would suggest to create a backup directory and get in the habit of copying any files with the date in the filename before you make changes. There have been many instances where this has come back to bite me in the past and I have learned my lesson over the years so save yourself some time, stress, and headaches.
    cd /etc/apache2
    mkdir backups
    mv apache2.conf backups/apache2.conf.09_25_2014
     Continue reading "Ubuntu Server – Apache 2.4 Upgrade Changes"

Carrier Access Adit 600 – Reset to Factory Defaults

Carrier Access Adit 600
Carrier Access Adit 600

Today I ran into a password issue on a refurbished piece of telco equipment that I got for a great price at refurbphoneexchange.com, the Carrier Access Adit 600.

Just a little background info, these units are great for converting a couple of T1s from a Sangoma or Digium card in an Asterisk server for up to 48 FXS ports and are very solid performance wise. When compared to a Rhino box or other similar device that provide the same functionality, it’s like 1/5th of the cost. As far as I know, the only downside is that they are out of production and there is a limited number of units out there. Also, I haven’t been able to find any firmware updates anywhere for these units on the interweb. The company has been bought and sold so many times it is hard to keep track of who to call for support. It was Dell Force 10 Networks but now the current company that owns rights to the product is Telmar but I’m still having trouble finding answers to my questions.
Continue reading “Carrier Access Adit 600 – Reset to Factory Defaults”

Bash Script – Sync a File to an Array of Hosts

#!/bin/bash
# Sync a file to a remote set of servers using scp and check using diff
# NOTE: This requires the use of 'sshpass' and IS insecure in nature
# It also assumes the user credentials are identical on all hosts
# and that they have the necessary permissions on the remote directory
# Author: Nathan Thomas
LOGFILE='/var/log/sync_files.log'
SSH_USER='non-root-user'
SSH_PASS='password'
CONF_FILE='/etc/appdir/myconfig.conf'
SERVERS=('server1.fqdn.com' 'server2.fqdn.com' 'server3.fqdn.com')
for HOST in "${SERVERS[@]}" ; do
        # NOTE: This won't work if the host keys are not already in the ssh cache
        # Flush ssh hosts - Either uncomment these two lines on first run or you could leave it uncommented for hosts that change addresses a lot
 Continue reading "Bash Script – Sync a File to an Array of Hosts"

Bash Script – Script Based MySQL Table Replication on an Array of Slaves

This bash script only uses row count and MySQL checksum to determine table consistency. I created this script because I wanted a different option rather than using MySQL replication. I initially had replication set up and working between six sites but it would tend to break from time to time so I needed a different solution. In my situation, my data was only being updated once or twice a week. This script should only be used in cases where you’re not overly concerned about your data consistency and row count and checksum are sufficient enough to suit your needs. If you need a more accurate consistency check of your table data, look into the Percona Toolkit.

#!/bin/bash
#
# Sync DB Tables w/o Replication
# Author: Nathan Thomas 01/16/2014

#------#
# VARS #
#------#
# Server to sync DB from
MASTER='master01.fqdn.com'
MUSER='username'
MPASS='password'
DBNAME='mydbname'
TBLNAME='mytablename'
DUMP='/tmp/mydumpfile.sql'
LOGFILE='/var/log/mysql/mysql_repl_check.log'
MAILTO='my_email_addr@fqdn.com'

# Array of slave hostnames separated by a space
declare -a SLAVE=('slave01.fqdn.com' 'slave02.fqdn.com' 'slave03.fqdn.com')
# Array of slave usernames in same order
declare -a SUSER=('username1' 'username2' 'username3')
# Array of slave passwords in same order
declare -a SPASS=('password1' 'password2' 'password3')

#-----------#
# FUNCTIONS #
#-----------#
# Check table exists
# params: $1=username $2=password $3=hostname
function tableExists() {
        echo "`date "+%a %b%e %T"` - Called function 'tableExists' on $3." >> ${LOGFILE}
        echo "`date "+%a %b%e %T"` - Running query to verify table '${TBLNAME}' exists in database '${DBNAME}' on $3." >> ${LOGFILE}
        local QUERY="SELECT COUNT(1) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='${DBNAME}' AND TABLE_NAME='${TBLNAME}'"
        local RESULT=`mysql -u $1 -p$2 -h $3 -Bse "$QUERY" 2>&1`
        local RETVAL="$?"
        echo "`date "+%a %b%e %T"` - Query on $3 retured the following value: '${RESULT}'" >> ${LOGFILE}
        echo "`date "+%a %b%e %T"` - Exit status of last command on $3 returned: '${RETVAL}'" >> ${LOGFILE}
        if [ "${RETVAL}" -eq "0" -a "${RESULT}" -eq "0" 2>/dev/null ] ; then  # Retval 0, query returned 0, hide stderr, Table missing
                echo "`date "+%a %b%e %T"` - Table '${TBLNAME}' does not exist in database '${DBNAME}' on $3." >> ${LOGFILE}
                echo "`date "+%a %b%e %T"` - Function 'tableExists' completed successfully on $3." >> ${LOGFILE}
                return 1  # No dice
        elif [ "${RETVAL}" -eq "0" -a "${RESULT}" -eq "1" 2>/dev/null ] ; then  # Retval 0, query returned 1, hide stderr, Table exists
                echo "`date "+%a %b%e %T"` - Table '${TBLNAME}' exists in database '${DBNAME}' on $3." >> ${LOGFILE}
                echo "`date "+%a %b%e %T"` - Function 'tableExists' completed successfully on $3." >> ${LOGFILE}
                return 0  # All good
        else  # Some other error
                echo "`date "+%a %b%e %T"` - Unable to determine table '${TBLNAME}' exists in database '${DBNAME}' on $3." >> ${LOGFILE}
                echo "`date "+%a %b%e %T"` - We either encountered an error code in the SQL data, had a problem connecting to MySQL, or the last command exited with a nonzero status." >> ${LOGFILE}
                echo "`date "+%a %b%e %T"` - Function 'tableExists' did not finish successfully on $3." >> ${LOGFILE}
                return 2  # No dice
        fi
}

# Get row count
# params: $1=username $2=password $3=hostname
function getRowCount() {
        echo "`date "+%a %b%e %T"` - Called function 'getRowCount' on $3." >> ${LOGFILE}
        echo "`date "+%a %b%e %T"` - Verifying table '${TBLNAME}' exists in database '${DBNAME}' on $3." >> ${LOGFILE}
        tableExists $1 $2 $3
        if [ "$?" -eq "0" ] ; then  # Retval 0, table exists
                echo "`date "+%a %b%e %T"` - Running query to obtain row count on table '${TBLNAME}' in database '${DBNAME}' on $3." >> ${LOGFILE}
                local QUERY="SELECT COUNT(id) FROM ${TBLNAME}"
                local RESULT=`mysql -u $1 -p$2 -h $3 ${DBNAME} -Bse "${QUERY}" 2>&1`
                local RETVAL="$?"
                echo "`date "+%a %b%e %T"` - Query on $3 retured the following value: '${RESULT}'" >> ${LOGFILE}
                echo "`date "+%a %b%e %T"` - Exit status of last command on $3 returned: '${RETVAL}'" >> ${LOGFILE}
                if [ "${RETVAL}" -eq "0" -a -n "${RESULT}" -a "${RESULT}" -eq "${RESULT}" 2>/dev/null ] ; then  # Retval 0, check for nonzero string, is numeric, hide stderr
                        echo "${RESULT}"
                        echo "`date "+%a %b%e %T"` - The row count on $3 is: '${RESULT}'" >> ${LOGFILE}
                        echo "`date "+%a %b%e %T"` - Function 'getRowCount' completed successfully on $3." >> ${LOGFILE}
                        return 0  # All good
                else
                        echo "`date "+%a %b%e %T"` - Unable to retrieve row count on $3." >> ${LOGFILE}
                        echo "`date "+%a %b%e %T"` - We either encountered an error code in the SQL data, had a problem connecting to MySQL, or the last command exited with a nonzero status." >> ${LOGFILE}
                        echo "`date "+%a %b%e %T"` - Function 'tableExists' did not finish successfully on $3." >> ${LOGFILE}
                        return 1  # No dice
                fi
        fi
}

# Get table checksum
# params: $1=username $2=password $3=hostname
function getTableChecksum() {
        echo "`date "+%a %b%e %T"` - Called function 'getTableChecksum' on $3." >> ${LOGFILE}
 Continue reading "Bash Script – Script Based MySQL Table Replication on an Array of Slaves"

Linux – Policy-Based Routing Enables the Use of Multiple IP Default Gateways

Props to this site for the helpful info.

1. Configure your first static IP Address and Gateway information as normal inside of /etc/network/interfaces. If you have multiple static IP’s in the same subnet using the same gateway you should be fine to add them as sub-interfaces with no problems.

auto eth0
iface eth0 inet static
        address 1.1.1.1
        netmask 255.255.255.0
        network 1.1.1.0
        broadcast 1.1.1.255
        dns-nameservers 2.2.2.2 3.3.3.3
        dns-search yourdomain.com
 Continue reading "Linux – Policy-Based Routing Enables the Use of Multiple IP Default Gateways"

Install MySQL Activity Report from Source

MySQL Activity Report is a handy database reporting tool that uses RRD (Round Robin Database) to display hourly, daily, weekly, and monthly graphs and gives helpful performance tuning recommendations for your MySQL installation. Here are the steps to install it from source on Ubuntu Server 12.04.3 while logged in as root. This assumes that you have the build-essentials, header files, etc necessary to build software already installed.

1. Change into your local source directory

cd /usr/local/src

2. Download the source files for rrdtool and mysqlard

wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.8.tar.gz
wget http://gert.sos.be/downloads/mysqlar/mysqlard-1.0.0.tar.gz

3. Unzip the files

tar -zxvf rrdtool-1.4.8.tar.gz
tar -zxvf mysqlard-1.0.0.tar.gz

4. Change into the rrd directory

cd rrdtool-1.4.8

5. Install dependencies

apt-get install libpango1.0-dev libxml2-dev

6. Build rrdtool (will install to the /opt/rrdtool-1.4.8 directory)
Continue reading “Install MySQL Activity Report from Source”

Bash Script – Move Asterisk Call Files into Spool Directory

After running into permission issues trying to get PHP’s shell_exec command to chown call files as the asterisk user(which only root can do), I decided to make this script.

As a side note, you should be able to get the shell_exec command to work using sudo by adding the www-data user to the sudoer’s file without a password but that wouldn’t work in my particular environment. The server I was working on was extremely outdated and didn’t even have sudo installed.

Add this to /etc/sudoers
www-data ALL=NOPASSWD: /path/to/script

The following code runs the script as a daemon. You will need to update rc to start this script at default run levels and also make sure to chmod +x this file to make it executable.

filename: /etc/init.d/mvcallfile

#!/bin/bash
# Move asterisk call file daemon startup script
# Author: Nathan Thomas

PROG=mvcallfile
 Continue reading "Bash Script – Move Asterisk Call Files into Spool Directory"

Startup Script for OpenMeetings Open-Source Video Conferencing Server

/etc/init.d/openmeetings startup script for Ubuntu Server 12.04.2
OpenMeetings Version 2.0-INCUBATING

A few notes:
– Make sure to change path for RED5_HOME variable
– Make sure to chmod +x the init script
– This assumes openmeetings is running under a user/group with the same name
– This assumes you are using libreoffice (not openoffice) for the whiteboard file import service

#!/bin/bash
#
# Author: Nathan Thomas
#
### BEGIN INIT INFO
# Provides:          red5
# Required-Start:    $local_fs $remote_fs $network $syslog $named $time
# Required-Stop:     $local_fs $remote_fs $network $syslog $named $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/stop OpenMeetings java based conferencing webapp
### END INIT INFO
PROG=red5
DESC="Red5 flash streaming server"
RED5_HOME=/usr/local/openmeetings
DAEMON=$RED5_HOME/$PROG.sh
PIDFILE=/var/run/$PROG.pid
# Plugin Variables
#OO_HOME=/usr/lib/openoffice/program
OO_HOME=/usr/lib/libreoffice/program
 Continue reading "Startup Script for OpenMeetings Open-Source Video Conferencing Server"