Skip to content

Instantly share code, notes, and snippets.

@dotmanila
Created October 7, 2011 01:45
Show Gist options
  • Save dotmanila/1269240 to your computer and use it in GitHub Desktop.
Save dotmanila/1269240 to your computer and use it in GitHub Desktop.
rtime init script
#!/bin/sh
# rtime daemon start/stop script.
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: Passive TCP response time analysis tool.
# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: mysql httpd memcached
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop rtime
# Description: Passive TCP response time analysis tool.
### END INIT INFO
#
# Use LSB init script functions for printing messages, if possible
#
lsb_functions="/lib/lsb/init-functions"
if [ -f $lsb_functions ] ; then
. $lsb_functions
else
log_success_msg()
{
echo " SUCCESS! $@"
}
log_failure_msg()
{
echo " ERROR! $@"
}
fi
PATH=/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin
export PATH
rtime="/usr/bin/rtime"
conf="/etc/rtime.conf"
opt=
datadir="/var/lib/rtime"
pidfile="/var/run/rtime.pid"
data="rtime-`date +\%Y-\%m-\%d-\%H_\%M_\%S`.db"
iterations=0
if [ -n "$2" ]; then conf=$2; fi
if [ ! -f $conf ] ; then
log_failure_msg "rtime.conf does not exist!"
exit 1
fi
while read line
do
key=(`echo $line|sed -n "s/^\([^#].*\)=.*/\1/p"`)
val=(`echo $line|sed -n "s/^[^#].*=\s*\(.*\)\s*/\1/p"`)
if [ -n "$key" ]; then
case $key in
read)
if [ -n "$val" ]; then
opt=$opt" "--read=$val
fi
;;
port)
if [ -n "$val" ]; then
opt=$opt" "--port=$val
data="rtime-`date +\%Y-\%m-\%d-\%H_\%M_\%S`-$val.db"
fi
;;
format)
if [ -n "$val" ]; then
opt=$opt" "--format=$val
fi
;;
header)
if [ -n "$val" ]; then
opt=$opt" "--header=$val
fi
;;
interval)
if [ -n "$val" ]; then
opt=$opt" "--interval=$val
fi
;;
iterations)
if [ -n "$val" ]; then
opt=$opt" "--iterations=$val
fi
;;
esac
if [ -n "$val" ]; then
export "$key=$val"
# echo "$key=$val"
fi
fi
done < $conf
if [[ ! -d $datadir || ! -w $datadir ]]; then
log_failure_msg "$datadir does not exist or not writeable!"
exit 1
fi
if [[ -z "$iterations" || "$iterations" -eq "0" ]]; then
opt="$opt --iterations=0"
if [ -n "$port" ]; then pidfile="/var/run/rtime-$port.pid"; fi
fi
start() {
echo "Starting rtime with $rtime $opt > $datadir/$data 2>/var/log/rtime.log & ..."
if [ -f "$pidfile" ]; then
log_failure_msg "rtime already running "
exit 1
fi
# Check if iterations is set, if not we create a pid file
$rtime $opt > $datadir/$data 2>/var/log/rtime.log &
if [ "$iterations" -eq "0" ]; then
rtimepid=$!
echo "$rtimepid" > $pidfile
echo $pidfile
fi
RETVAL=$?
}
stop() {
kill -9 `cat $pidfile`
RETVAL=$?
if [[ "$RETVAL" -eq "0" && "$iterations" -eq "0" ]]; then rm -rf $pidfile; fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo $"Usage: rtime {start|stop [/path/to/conf.file]}"
exit 1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment