Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

etc_init.d_collectd 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #! /bin/bash
  2. #
  3. # collectd - start and stop the statistics collection daemon
  4. # http://collectd.org/
  5. #
  6. # Copyright (C) 2005-2006 Florian Forster <octo@verplant.org>
  7. # Copyright (C) 2006-2009 Sebastian Harl <tokkee@debian.org>
  8. #
  9. ### BEGIN INIT INFO
  10. # Provides: collectd
  11. # Required-Start: $local_fs $remote_fs
  12. # Required-Stop: $local_fs $remote_fs
  13. # Should-Start: $network $named $syslog $time cpufrequtils
  14. # Should-Stop: $network $named $syslog
  15. # Default-Start: 2 3 4 5
  16. # Default-Stop: 0 1 6
  17. # Short-Description: manage the statistics collection daemon
  18. # Description: collectd is the statistics collection daemon.
  19. # It is a small daemon which collects system information
  20. # periodically and provides mechanisms to monitor and store
  21. # the values in a variety of ways.
  22. ### END INIT INFO
  23. . /lib/lsb/init-functions
  24. export PATH=/opt/collectd/sbin:/opt/collectd/bin:/sbin:/bin:/usr/sbin:/usr/bin
  25. DISABLE=0
  26. DESC="statistics collection and monitoring daemon"
  27. NAME=collectd
  28. DAEMON=/opt/collectd/sbin/collectd
  29. CONFIGFILE=/opt/collectd/etc/collectd.conf
  30. PIDFILE=/opt/collectd/var/run/collectd.pid
  31. USE_COLLECTDMON=1
  32. COLLECTDMON_DAEMON=/opt/collectd/sbin/collectdmon
  33. COLLECTDMON_PIDFILE=/opt/collectd/var/run/collectdmon.pid
  34. MAXWAIT=30
  35. # Gracefully exit if the package has been removed.
  36. test -x $DAEMON || exit 0
  37. if [ -r /etc/default/$NAME ]; then
  38. . /etc/default/$NAME
  39. fi
  40. if test "$ENABLE_COREFILES" == 1; then
  41. ulimit -c unlimited
  42. fi
  43. if test "$USE_COLLECTDMON" == 1; then
  44. _PIDFILE="$COLLECTDMON_PIDFILE"
  45. else
  46. _PIDFILE="$PIDFILE"
  47. fi
  48. # return:
  49. # 0 if config is fine
  50. # 1 if there is a syntax error
  51. # 2 if there is no configuration
  52. check_config() {
  53. if test ! -e "$CONFIGFILE"; then
  54. return 2
  55. fi
  56. if ! $DAEMON -t -C "$CONFIGFILE"; then
  57. return 1
  58. fi
  59. return 0
  60. }
  61. # return:
  62. # 0 if the daemon has been started
  63. # 1 if the daemon was already running
  64. # 2 if the daemon could not be started
  65. # 3 if the daemon was not supposed to be started
  66. d_start() {
  67. if test "$DISABLE" != 0; then
  68. # we get here during restart
  69. log_progress_msg "disabled by /etc/default/$NAME"
  70. return 3
  71. fi
  72. if test ! -e "$CONFIGFILE"; then
  73. # we get here during restart
  74. log_progress_msg "disabled, no configuration ($CONFIGFILE) found"
  75. return 3
  76. fi
  77. check_config
  78. rc="$?"
  79. if test "$rc" -ne 0; then
  80. log_progress_msg "not starting, configuration error"
  81. return 2
  82. fi
  83. if test "$USE_COLLECTDMON" == 1; then
  84. start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
  85. --exec $COLLECTDMON_DAEMON -- -P "$_PIDFILE" -- -C "$CONFIGFILE" \
  86. || return 2
  87. else
  88. start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
  89. --exec $DAEMON -- -C "$CONFIGFILE" -P "$_PIDFILE" \
  90. || return 2
  91. fi
  92. return 0
  93. }
  94. still_running_warning="
  95. WARNING: $NAME might still be running.
  96. In large setups it might take some time to write all pending data to
  97. the disk. You can adjust the waiting time in /etc/default/collectd."
  98. # return:
  99. # 0 if the daemon has been stopped
  100. # 1 if the daemon was already stopped
  101. # 2 if daemon could not be stopped
  102. d_stop() {
  103. PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
  104. start-stop-daemon --stop --quiet --oknodo --pidfile "$_PIDFILE"
  105. rc="$?"
  106. if test "$rc" -eq 2; then
  107. return 2
  108. fi
  109. sleep 1
  110. if test -n "$PID" && kill -0 $PID 2> /dev/null; then
  111. i=0
  112. while kill -0 $PID 2> /dev/null; do
  113. i=$(( $i + 2 ))
  114. echo -n " ."
  115. if test $i -gt $MAXWAIT; then
  116. log_progress_msg "$still_running_warning"
  117. return 2
  118. fi
  119. sleep 2
  120. done
  121. return "$rc"
  122. fi
  123. return "$rc"
  124. }
  125. case "$1" in
  126. start)
  127. log_daemon_msg "Starting $DESC" "$NAME"
  128. d_start
  129. case "$?" in
  130. 0|1) log_end_msg 0 ;;
  131. 2) log_end_msg 1 ;;
  132. 3) log_end_msg 255; true ;;
  133. *) log_end_msg 1 ;;
  134. esac
  135. ;;
  136. stop)
  137. log_daemon_msg "Stopping $DESC" "$NAME"
  138. d_stop
  139. case "$?" in
  140. 0|1) log_end_msg 0 ;;
  141. 2) log_end_msg 1 ;;
  142. esac
  143. ;;
  144. status)
  145. status_of_proc -p "$_PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
  146. ;;
  147. restart|force-reload)
  148. log_daemon_msg "Restarting $DESC" "$NAME"
  149. check_config
  150. rc="$?"
  151. if test "$rc" -eq 1; then
  152. log_progress_msg "not restarting, configuration error"
  153. log_end_msg 1
  154. exit 1
  155. fi
  156. d_stop
  157. rc="$?"
  158. case "$rc" in
  159. 0|1)
  160. sleep 1
  161. d_start
  162. rc2="$?"
  163. case "$rc2" in
  164. 0|1) log_end_msg 0 ;;
  165. 2) log_end_msg 1 ;;
  166. 3) log_end_msg 255; true ;;
  167. *) log_end_msg 1 ;;
  168. esac
  169. ;;
  170. *)
  171. log_end_msg 1
  172. ;;
  173. esac
  174. ;;
  175. *)
  176. echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
  177. exit 3
  178. ;;
  179. esac
  180. # vim: syntax=sh noexpandtab sw=4 ts=4 :