Skip to content

Instantly share code, notes, and snippets.

@haukurk
Created October 13, 2014 13:28
Show Gist options
  • Save haukurk/ae9415941d30ce07e4fc to your computer and use it in GitHub Desktop.
Save haukurk/ae9415941d30ce07e4fc to your computer and use it in GitHub Desktop.
Clean manhattan processes.
#!/usr/bin/ksh
####################################################################################
# This script was created for Samskip, by Haukur Kristinsson <haukur@hauxi.is> 2014.
# It purpose is to ease the task of cleaning after restarting the PKMS backend.
#
# If you have problems with it please contact Haukur.
#
# Revs:
# 13 Oct 2014 - First Rev.
#
#####################################################
# Logging Settings
##########################################################
logdir=/var/log # /var/log/shellscripts
logfile=${0#*\.}.log # see note in _log_ function
logfile=${logfile#*\/} # strip possible leading junk
integer sizelimit=10000 # 10Mb
filemode=640 # 644 for all access
ts=`/bin/date +%F-%T` # 2010-01-24-23:10:04
stdout=TRUE # Print also to STDOUT.
##########################################################
# Logging Core
##########################################################
_log_() {
_rotate_ $logdir/$logfile
mkdir -p $logdir
# Note that we do not chmod the $logdir
# because root could chmod /tmp and we
# would be in a pretty pickle!
print -- $ts $* >>$logdir/$logfile
# For a "unified" log, make the logfile name
# a string constant, and then use $0 in the
# log entry, i.e.:
# print -- "$ts \($0\) - $*" >>$logdir/$logfile
# print to stdout if you want that
# We should chmod the log file however
chmod $filemode $logdir/$logfile >/dev/null 2>&1
}
_rotate_() {
typeset size i
if [[ -f "$1" ]]
then
OIFS="$IFS"
IFS=' '
set -A size `ls -s "$1"`
if ((${size[0]} > $sizelimit))
then
for i in {8..1}
do
if [[ -f "$1.$i" ]]
then
mv -f $1.$i $1.$((i + 1))
fi
done
mv -f $1 $1.1
fi
IFS="$OIFS"
fi
}
#####################
usage()
#####################
{
print clean_manhattan_procs - a helper to clean processes after PKMS restart.
print "usage: clean_manhattan_procs"
}
##################
if_error()
##################
{
if [[ $? -ne 0 ]]; then # check return code passed to function
print "$1" # if rc > 0 then print error msg and quit
exit $?
fi
}
$(_log_ "starting cleaning procedures for manhattan..") && print "starting cleaning procedures for manhattan.."
print "killing htsam processes"
ps -ef | grep htsam | grep -v grep | awk {'print $2'} | while read pid; do
$(_log_ "killing $pid") && print "killing $pid"
kill -9 $pid
done
print "killing vm proccesses"
ps -ef | grep wm | grep -v ksh | grep -v grep | awk {'print $2'} | while read pid; do
$(_log_ "killing $pid") && print "killing $pid"
kill -9 $pid
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment