2006-01-26 00:37:29 -05:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# $Id: rsyncd-stop.template,v 1.3 2005/06/20 20:43:55 billa Exp $
|
|
|
|
# $Source: /cvs/main/searching/solar-tools/rsyncd-stop.template,v $
|
|
|
|
# $Name: r20050725_standardized_server_enabled $
|
|
|
|
#
|
|
|
|
# Shell script to stop rsyncd on master SOLAR server
|
|
|
|
|
|
|
|
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
|
|
|
|
|
|
|
|
# sudo to app user if necessary
|
|
|
|
if [[ $(whoami) != app ]]
|
|
|
|
then
|
|
|
|
sudo -u app $0 "$@"
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
oldwhoami=$(who -m | cut -d' ' -f1 | sed -e's/^.*!//')
|
|
|
|
|
|
|
|
if [[ "${oldwhoami}" == "" ]]
|
|
|
|
then
|
|
|
|
oldwhoami=`ps h -Hfp $(pgrep -g0 ${0##*/}) | tail -1|cut -f1 -d" "`
|
|
|
|
fi
|
|
|
|
|
|
|
|
prog=${0##*/}
|
|
|
|
log=logs/rsyncd.log
|
|
|
|
|
|
|
|
# define usage string
|
|
|
|
USAGE="\
|
|
|
|
usage: $prog [ -v ]
|
|
|
|
-v increase verbosity
|
|
|
|
"
|
|
|
|
|
|
|
|
cd ${0%/*}/../..
|
|
|
|
SERVER_ROOT=$(pwd)
|
|
|
|
|
|
|
|
unset verbose
|
|
|
|
|
|
|
|
# parse args
|
|
|
|
originalargs="$@"
|
|
|
|
while getopts v OPTION
|
|
|
|
do
|
|
|
|
case $OPTION in
|
|
|
|
v)
|
|
|
|
verbose="v"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$USAGE"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(( OPTIND - 1 ))
|
|
|
|
|
|
|
|
function timeStamp
|
|
|
|
{
|
|
|
|
date +'%Y/%m/%d %H:%M:%S'
|
|
|
|
}
|
|
|
|
|
|
|
|
function logMessage
|
|
|
|
{
|
|
|
|
echo $(timeStamp) $@>>$log
|
|
|
|
if [[ -n ${verbose} ]]
|
|
|
|
then
|
|
|
|
echo $@
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
logMessage stopped by $oldwhoami
|
|
|
|
logMessage command: $0 $originalargs
|
|
|
|
|
|
|
|
# get PID from file
|
|
|
|
pid=$(<$SERVER_ROOT/logs/rsyncd.pid)
|
|
|
|
if [[ -z $pid ]]
|
|
|
|
then
|
|
|
|
logMessage "unable to get rsyncd's PID"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
kill $pid
|
|
|
|
|
|
|
|
# wait until rsyncd dies or we time out
|
|
|
|
dead=0
|
|
|
|
timer=0
|
|
|
|
timeout=300
|
|
|
|
while (( ! dead && timer < timeout ))
|
|
|
|
do
|
2006-02-27 20:18:40 -05:00
|
|
|
if ps -eo pid | grep -qw $pid
|
2006-01-26 00:37:29 -05:00
|
|
|
then
|
|
|
|
kill $pid
|
|
|
|
(( timer++ ))
|
|
|
|
sleep 1
|
|
|
|
else
|
|
|
|
dead=1
|
|
|
|
fi
|
|
|
|
done
|
2006-02-27 20:18:40 -05:00
|
|
|
if ps -eo pid | grep -qw $pid
|
2006-01-26 00:37:29 -05:00
|
|
|
then
|
|
|
|
logMessage rsyncd failed to stop after $timeout seconds
|
|
|
|
exit 3
|
|
|
|
fi
|