Newer
Older
monitord / scripts / monitord-start-stop
  1. #!/bin/sh
  2. #
  3. # monitord This is the init script for starting monitord (ZVEI/POCSAG receiver)
  4. #
  5. # chkconfig: - 66 19
  6. # description: monitord
  7. # processname: monitord
  8. # pidfile: /var/run/monitord.pid
  9. #
  10. # basically taken from /etc/init.d/postgresql for CentOS 6.2
  11.  
  12. # load functions
  13. . /etc/rc.d/init.d/functions
  14.  
  15. NAME=`basename $0`
  16.  
  17. if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]
  18. then
  19. NAME=${NAME:3}
  20. fi
  21.  
  22. # SELinux
  23. if [ -x /sbin/runuser ]
  24. then
  25. SU=runuser
  26. else
  27. SU=su
  28. fi
  29.  
  30. MONITORD=/opt/monitord/monitord
  31. MONITORD_USER=monitord
  32. MONITORD_CONFIG=/opt/monitord/monitord.xml
  33. MONITORD_OPTS=""
  34. MONITORD_STARTUP_LOG=/tmp/monitord-startup.log
  35.  
  36. if [[ ! -x $MONITORD ]]
  37. then
  38. echo
  39. echo "$MONITORD is missing or not executable"
  40. echo
  41. exit 1
  42. fi
  43.  
  44. lockfile="/var/lock/subsys/${NAME}"
  45. pidfile="/var/run/monitord.pid"
  46.  
  47. script_result=0
  48.  
  49. start() {
  50. if [ -z "$1" ]
  51. then
  52. echo "Waiting 15 seconds for coming up ActiveMQ..."
  53. sleep 15
  54. fi
  55.  
  56. MONITORD_START="Starting monitord..."
  57. STARTUP_LINE="$MONITORD -c $MONITORD_CONFIG$MONITORD_OPTS"
  58. $SU -c "$STARTUP_LINE &" - $MONITORD_USER >> "$MONITORD_STARTUP_LOG" 2>&1 #< /dev/null
  59. sleep 2
  60. pid=`ps -ef | grep "$STARTUP_LINE" | grep -v "grep" | awk '{ print \$2 }'`
  61.  
  62. if [ "x$pid" != x ]
  63. then
  64. success "$MONITORD_START"
  65. touch "$lockfile"
  66. echo $pid > "$pidfile"
  67. echo
  68. else
  69. failure "$MONITORD_START"
  70. echo
  71. script_result=1
  72. fi
  73. }
  74.  
  75. stop() {
  76. echo -n "Stopping monitord service: "
  77. if [ -e "$lockfile" ]
  78. then
  79. kill `cat $pidfile`
  80. ret=$?
  81.  
  82. if [ $ret -eq 0 ]
  83. then
  84. echo_success
  85. rm -f "$pidfile"
  86. rm -f "$lockfile"
  87. else
  88. echo_failure
  89. script_result=1
  90. fi
  91. else
  92. echo_success
  93. fi
  94. echo
  95. }
  96.  
  97. restart() {
  98. stop
  99. start
  100. }
  101.  
  102. status() {
  103. if [ -f $pidfile ]
  104. then
  105. pid=`cat $pidfile`
  106.  
  107. if [ "x$pid" != "x" ]
  108. then
  109. pidtest=`ps aux | grep "monitord" | grep -v "grep" | grep -v "monitord status"`
  110.  
  111. if [ "x$pidtest" = "x" ]
  112. then
  113. rm -f $pidfile
  114. echo "Removed stale pid file $pidfile"
  115. pid=""
  116. else
  117. echo "Monitord running"
  118. return 0
  119. fi
  120.  
  121. fi
  122. fi
  123.  
  124. echo "Monitord not started"
  125. exit 1
  126. }
  127.  
  128.  
  129. case "$1" in
  130. start)
  131. start
  132. ;;
  133. start-force)
  134. start now
  135. ;;
  136. stop)
  137. stop
  138. ;;
  139. restart)
  140. restart
  141. ;;
  142. status)
  143. status
  144. ;;
  145. *)
  146. echo $"Usage: $0 (start|stop|restart|status)"
  147. exit 2
  148. esac
  149.  
  150. exit $script_result