Guest User

Untitled

a guest
Jun 18th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: monit
  4. # Required-Start: $remote_fs
  5. # Required-Stop: $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: service and resource monitoring daemon
  9. ### END INIT INFO
  10. # /etc/init.d/monit start and stop monit daemon monitor process.
  11. # Fredrik Steen, stone@debian.org
  12. # Stefan Alfredsson, alfs@debian.org
  13.  
  14. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  15. DAEMON=/usr/sbin/monit
  16. CONFIG="/etc/monit/monitrc"
  17. DELAY="/etc/monit/monit_delay"
  18. NAME=monit
  19. DESC="daemon monitor"
  20.  
  21. # Check if DAEMON binary exist
  22. test -f $DAEMON || exit 0
  23.  
  24. if [ -f "/etc/default/monit" ]; then
  25. . /etc/default/monit
  26. fi
  27.  
  28. ARGS="-c $CONFIG -s /var/lib/monit/monit.state"
  29.  
  30. monit_not_configured () {
  31. printf "%b\n" "monit won't be started/stopped\n\tunless it it's configured"
  32. if [ "$1" != "stop" ]
  33. then
  34. printf "%b\n" "\tplease configure monit and then edit /etc/default/monit"
  35. printf "%b\n" "\tand set the \"startup\" variable to 1 in order to allow "
  36. printf "%b\n" "\tmonit to start"
  37. fi
  38. exit 0
  39. }
  40.  
  41. monit_check_config () {
  42. # Check for emtpy config, probably default configfile.
  43. if [ "`grep -s -v \"^#\" $CONFIG`" = "" ]; then
  44. echo "empty config, please edit $CONFIG."
  45. exit 0
  46. fi
  47. }
  48.  
  49. monit_check_perms () {
  50. # Check the permission on configfile.
  51. # The permission must not have more than -rwx------ (0700) permissions.
  52.  
  53. # Skip checking, fix perms instead.
  54. /bin/chmod go-rwx $CONFIG
  55.  
  56. }
  57.  
  58. monit_delayed_monitoring () {
  59. if [ -x $DELAY ]; then
  60. $DELAY &
  61. elif [ -f $DELAY ]; then
  62. echo
  63. echo "[WARNING] A delayed start file exists ($DELAY) but it is not executable."
  64. fi
  65. }
  66.  
  67. monit_check_syntax () {
  68. $DAEMON -t 2>/dev/null >/dev/null
  69. if [ $? -eq 1 ] ; then
  70. echo "Syntax error:"
  71. $DAEMON -t
  72. exit 0
  73. fi
  74. }
  75.  
  76.  
  77. monit_checks () {
  78. # Check if startup variable is set to 1, if not we exit.
  79. if [ "$startup" != "1" ]; then
  80. monit_not_configured $1
  81. fi
  82. # Check for emtpy configfile
  83. monit_check_config
  84. # Check permissions of configfile
  85. monit_check_perms
  86. # Check syntax of config file
  87. monit_check_syntax
  88. }
  89.  
  90. case "$1" in
  91. start)
  92. echo -n "Starting $DESC: "
  93. monit_checks $1
  94. echo -n "$NAME"
  95. start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
  96. --exec $DAEMON > /dev/null 2>&1 -- $ARGS
  97. monit_delayed_monitoring
  98. echo "."
  99. ;;
  100. stop)
  101. echo -n "Stopping $DESC: "
  102. #monit_checks $1
  103. echo -n "$NAME"
  104. start-stop-daemon --retry 5 --oknodo --stop --quiet --pidfile /var/run/$NAME.pid \
  105. --exec $DAEMON > /dev/null 2>&1
  106. echo "."
  107. ;;
  108. restart|force-reload)
  109. $0 stop
  110. $0 start
  111. ;;
  112. syntax)
  113. monit_check_syntax
  114. ;;
  115. *)
  116. N=/etc/init.d/$NAME
  117. echo "Usage: $N {start|stop|restart|force-reload|syntax}" >&2
  118. exit 1
  119. ;;
  120. esac
  121.  
  122. exit 0
Add Comment
Please, Sign In to add comment