banana0 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. #
  3. # Monkey HTTP Daemon - Banana Script
  4. # -----------------------------------
  5. # This script allow you to control monkey. Written by Eduardo Silva
  6. # ----------------------------
  7. # Date : 2002/09/01.
  8. # ----------------------------
  9. #
  10. # Use: ./banana OPTION
  11. #
  12. # Options available to banana:
  13. #
  14. # start -> start monkey
  15. # restart -> restart monkey
  16. # stop -> stop monkey if this is running
  17. # help -> what do u think ?
  18. PIDFILE="/root/monkey/logs/monkey.pid"
  19. BINMONKEY="/root/monkey/bin/monkey"
  20. CONFIGFILE="/root/monkey/conf"
  21. for arg in $*; do
  22. case "$arg" in
  23. -*=*) optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  24. *) optarg= ;;
  25. esac
  26. if ! test -f $PIDFILE ; then
  27. STATUS="no"
  28. else
  29. PIDMONKEY=`cat $PIDFILE`
  30. if ! kill -0 $PIDMONKEY 2>/dev/null; then
  31. STATUS="no"
  32. else
  33. STATUS="yes"
  34. fi
  35. fi
  36. case "$arg" in
  37. start)
  38. if [ "$STATUS" == "yes" ] ; then
  39. echo "Monkey is running... (PID=$PIDMONKEY)"
  40. exit 1
  41. fi
  42. if ! test -x $BINMONKEY ; then
  43. echo "Error: I can't run binary file"
  44. exit 1
  45. else
  46. if $BINMONKEY -Dc "$CONFIGFILE" 2>/dev/null ; then
  47. echo "Running Monkey -> OK"
  48. exit 0
  49. fi
  50. fi
  51. ;;
  52. stop)
  53. if [ "$STATUS" == "no" ]; then
  54. echo "Monkey is not running."
  55. exit 1
  56. fi
  57. kill $PIDMONKEY
  58. rm -rf $PIDFILE > /dev/null
  59. echo "Monkey stopped ($PIDMONKEY)"
  60. exit 0
  61. ;;
  62. restart)
  63. if [ "$STATUS" == "yes" ]; then
  64. if ! kill $PIDMONKEY > /dev/null ; then
  65. killall -9 monkey
  66. else
  67. echo -n "Stopping Monkey... "
  68. fi
  69. else
  70. echo -n "Monkey is not running... "
  71. fi
  72. if ! test -x $BINMONKEY ; then
  73. echo "Error: I can't run binary file"
  74. exit 1
  75. else
  76. $BINMONKEY -Dc "$CONFIGFILE" > /dev/null
  77. echo "Restarting -> OK"
  78. exit 0
  79. fi
  80. ;;
  81. *)
  82. echo "Use : banana [start|stop|restart|help]"
  83. exit 1
  84. ;;
  85. esac
  86. done
  87. echo "Use : banana [start|stop|restart|help]"
  88. exit 0