stopdaemons.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # StatusNet - a distributed open-source microblogging tool
  3. # Copyright (C) 2008, 2009, StatusNet, Inc.
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. # This program tries to stop the daemons for GNU social that were
  18. # previously started by startdaemons.sh
  19. ARGSG=
  20. SITENAME=
  21. SITE=
  22. ID="*"
  23. # stopdaemons.sh [server [path]]
  24. if [ $# -gt 0 ] ; then
  25. SITENAME="$1"
  26. SITE="-s$SITENAME"
  27. ID=`echo $SITENAME | sed s/\\\\./_/g`
  28. ARGSG="$ARGSG -s$1"
  29. fi
  30. if [ $# -gt 1 ]; then
  31. ARGSG="$ARGSG -p$2"
  32. fi
  33. SDIR=`dirname $0`
  34. DIR=`php $SDIR/getpiddir.php $SITE`
  35. DAEMONS=`php $SDIR/getvaliddaemons.php $ARGSG`
  36. for f in $DAEMONS; do
  37. f=$(basename $f .php)
  38. FILES="$DIR/$f.$ID.pid"
  39. for ff in "$FILES" ; do
  40. PID=`cat $ff 2>/dev/null`
  41. if [ -n "$PID" ] ; then
  42. echo -n "Stopping $f ($PID)..."
  43. if kill -3 $PID 2>/dev/null ; then
  44. count=0
  45. while kill -0 $PID 2>/dev/null ; do
  46. sleep 1
  47. count=$(($count + 1))
  48. if [ $count -gt 5 ]; then break; fi
  49. done
  50. if kill -9 $PID 2>/dev/null ; then
  51. echo "FORCIBLY TERMINATED"
  52. else
  53. echo "STOPPED CLEANLY"
  54. fi
  55. else
  56. echo "NOT FOUND"
  57. fi
  58. fi
  59. rm -f $ff
  60. done
  61. done