stopdaemons.sh 1.73 KB
Newer Older
1
#!/bin/bash
2

3
# StatusNet - a distributed open-source microblogging tool
4

5
# Copyright (C) 2008, 2009, StatusNet, Inc.
6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

20
# This program tries to stop the daemons for GNU social that were
21 22
# previously started by startdaemons.sh

23
ARGSG=
24 25 26 27
SITENAME=
SITE=
ID="*"

28 29
# stopdaemons.sh [server [path]]

30 31 32 33
if [ $# -gt 0 ] ; then
	SITENAME="$1"
	SITE="-s$SITENAME"
	ID=`echo $SITENAME | sed s/\\\\./_/g`
34 35 36 37 38
	ARGSG="$ARGSG -s$1"
fi

if [ $# -gt 1 ]; then
	ARGSG="$ARGSG -p$2"
39 40
fi

41
SDIR=`dirname $0`
42
DIR=`php $SDIR/getpiddir.php $SITE`
43

44
DAEMONS=`php $SDIR/getvaliddaemons.php $ARGSG`
45 46 47

for f in $DAEMONS; do
    f=$(basename $f .php)
48

49 50
	FILES="$DIR/$f.$ID.pid"

51 52
	for ff in "$FILES" ; do

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
	 	PID=`cat $ff 2>/dev/null`
		if [ -n "$PID" ] ; then
		 	echo -n "Stopping $f ($PID)..."
			if kill -3 $PID 2>/dev/null ; then
				count=0
				while kill -0 $PID 2>/dev/null ;  do
					sleep 1
					count=$(($count + 1))
					if [ $count -gt 5 ]; then break; fi
				done
				if kill -9 $PID 2>/dev/null ; then
					echo "FORCIBLY TERMINATED"
				else
					echo "STOPPED CLEANLY"
				fi
			else
				echo "NOT FOUND"
			fi
71 72 73 74
		fi
		rm -f $ff
	done
done