collectd.init 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/bin/sh
  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. . /etc/init.d/functions
  24. export PATH=/sbin:/bin:/usr/sbin:/usr/bin
  25. DISABLE=0
  26. NAME=collectd
  27. DAEMON=/usr/sbin/collectd
  28. CONFIGFILE=/etc/collectd.conf
  29. PIDFILE=/var/run/collectd.pid
  30. USE_COLLECTDMON=1
  31. COLLECTDMON_DAEMON=/usr/sbin/collectdmon
  32. COLLECTDMON_PIDFILE=/var/run/collectdmon.pid
  33. MAXWAIT=30
  34. # Gracefully exit if the package has been removed.
  35. test -x $DAEMON || exit 0
  36. if [ -r /etc/default/$NAME ]; then
  37. . /etc/default/$NAME
  38. fi
  39. if test "$ENABLE_COREFILES" = 1; then
  40. ulimit -c unlimited
  41. fi
  42. if test "$USE_COLLECTDMON" = 1; then
  43. _PIDFILE="$COLLECTDMON_PIDFILE"
  44. else
  45. _PIDFILE="$PIDFILE"
  46. fi
  47. # return:
  48. # 0 if config is fine
  49. # 1 if there is a syntax error
  50. # 2 if there is no configuration
  51. check_config() {
  52. if test ! -e "$CONFIGFILE"; then
  53. return 2
  54. fi
  55. if ! $DAEMON -t -C "$CONFIGFILE"; then
  56. return 1
  57. fi
  58. return 0
  59. }
  60. # return:
  61. # 0 if the daemon has been started
  62. # 1 if the daemon was already running
  63. # 2 if the daemon could not be started
  64. # 3 if the daemon was not supposed to be started
  65. d_start() {
  66. if test "$DISABLE" != 0; then
  67. # we get here during restart
  68. echo "disabled by /etc/default/$NAME"
  69. return 3
  70. fi
  71. if test ! -e "$CONFIGFILE"; then
  72. # we get here during restart
  73. echo "disabled, no configuration ($CONFIGFILE) found"
  74. return 3
  75. fi
  76. check_config
  77. rc="$?"
  78. if test "$rc" -ne 0; then
  79. echo "not starting, configuration error"
  80. return 2
  81. fi
  82. if test "$USE_COLLECTDMON" = 1; then
  83. start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
  84. --exec $COLLECTDMON_DAEMON -- -P "$_PIDFILE" -- -C "$CONFIGFILE" \
  85. || return 2
  86. else
  87. start-stop-daemon --start --quiet --oknodo --pidfile "$_PIDFILE" \
  88. --exec $DAEMON -- -C "$CONFIGFILE" -P "$_PIDFILE" \
  89. || return 2
  90. fi
  91. return 0
  92. }
  93. still_running_warning="
  94. WARNING: $NAME might still be running.
  95. In large setups it might take some time to write all pending data to
  96. the disk. You can adjust the waiting time in /etc/default/collectd."
  97. # return:
  98. # 0 if the daemon has been stopped
  99. # 1 if the daemon was already stopped
  100. # 2 if daemon could not be stopped
  101. d_stop() {
  102. PID=$( cat "$_PIDFILE" 2> /dev/null ) || true
  103. start-stop-daemon --stop --quiet --oknodo --pidfile "$_PIDFILE"
  104. rc="$?"
  105. if test "$rc" -eq 2; then
  106. return 2
  107. fi
  108. sleep 1
  109. if test -n "$PID" && kill -0 $PID 2> /dev/null; then
  110. i=0
  111. while kill -0 $PID 2> /dev/null; do
  112. i=$(( $i + 2 ))
  113. echo -n " ."
  114. if test $i -gt $MAXWAIT; then
  115. echo "$still_running_warning"
  116. return 2
  117. fi
  118. sleep 2
  119. done
  120. return "$rc"
  121. fi
  122. return "$rc"
  123. }
  124. # return:
  125. # 0 if the daemon is running
  126. # 3 if the daemon is stopped
  127. d_status(){
  128. if test "$USE_COLLECTDMON" = 1; then
  129. status $COLLECTDMON_DAEMON
  130. else
  131. status $DAEMON
  132. fi
  133. }
  134. case "$1" in
  135. start)
  136. echo -n "Starting $NAME"
  137. d_start
  138. case "$?" in
  139. 0|1) echo "." ;;
  140. *) exit 1 ;;
  141. esac
  142. ;;
  143. stop)
  144. echo -n "Stopping $NAME"
  145. d_stop
  146. case "$?" in
  147. 0|1) echo "." ;;
  148. *) exit 1 ;;
  149. esac
  150. ;;
  151. status)
  152. d_status
  153. ;;
  154. restart|force-reload)
  155. echo -n "Restarting $NAME"
  156. check_config
  157. rc="$?"
  158. if test "$rc" -eq 1; then
  159. echo "not restarting, configuration error"
  160. exit 1
  161. fi
  162. d_stop
  163. rc="$?"
  164. case "$rc" in
  165. 0|1)
  166. sleep 1
  167. d_start
  168. rc2="$?"
  169. case "$rc2" in
  170. 0|1) echo "." ;;
  171. *) exit 1 ;;
  172. esac
  173. ;;
  174. *)
  175. exit 1
  176. ;;
  177. esac
  178. ;;
  179. *)
  180. echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
  181. exit 3
  182. ;;
  183. esac
  184. # vim: syntax=sh noexpandtab sw=4 ts=4 :