IRC bot that reports on Gerrit events
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.

gerritbot.init 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: gerritbot
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Gerrit IRC Bot
  9. # Description: Announces Gerrit events to IRC
  10. ### END INIT INFO
  11. # Author: James Blair <james.blair@rackspace.com>
  12. # Do NOT "set -e"
  13. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  14. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. DESC="GerritBot"
  16. NAME=gerritbot
  17. DAEMON=/usr/local/bin/$NAME
  18. DAEMON_ARGS="/home/gerrit2/gerritbot.config"
  19. PIDFILE=/var/run/$NAME/$NAME.pid
  20. SCRIPTNAME=/etc/init.d/$NAME
  21. USER=gerrit2
  22. # Exit if the package is not installed
  23. [ -x "$DAEMON" ] || exit 0
  24. # Read configuration variable file if it is present
  25. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  26. # Load the VERBOSE setting and other rcS variables
  27. . /lib/init/vars.sh
  28. # Define LSB log_* functions.
  29. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  30. . /lib/lsb/init-functions
  31. #
  32. # Function that starts the daemon/service
  33. #
  34. do_start()
  35. {
  36. # Return
  37. # 0 if daemon has been started
  38. # 1 if daemon was already running
  39. # 2 if daemon could not be started
  40. mkdir -p /var/run/$NAME
  41. chown $USER /var/run/$NAME
  42. start-stop-daemon --start --quiet --pidfile $PIDFILE -c $USER --exec $DAEMON --test > /dev/null \
  43. || return 1
  44. start-stop-daemon --start --quiet --pidfile $PIDFILE -c $USER --exec $DAEMON -- \
  45. $DAEMON_ARGS \
  46. || return 2
  47. # Add code here, if necessary, that waits for the process to be ready
  48. # to handle requests from services started subsequently which depend
  49. # on this one. As a last resort, sleep for some time.
  50. }
  51. #
  52. # Function that stops the daemon/service
  53. #
  54. do_stop()
  55. {
  56. # Return
  57. # 0 if daemon has been stopped
  58. # 1 if daemon was already stopped
  59. # 2 if daemon could not be stopped
  60. # other if a failure occurred
  61. start-stop-daemon --stop --signal 9 --pidfile $PIDFILE
  62. RETVAL="$?"
  63. [ "$RETVAL" = 2 ] && return 2
  64. rm -f /var/run/$NAME/*
  65. return "$RETVAL"
  66. }
  67. #
  68. # Function that sends a SIGHUP to the daemon/service
  69. #
  70. do_reload() {
  71. #
  72. # If the daemon can reload its configuration without
  73. # restarting (for example, when it is sent a SIGHUP),
  74. # then implement that here.
  75. #
  76. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  77. return 0
  78. }
  79. case "$1" in
  80. start)
  81. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  82. do_start
  83. case "$?" in
  84. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  85. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  86. esac
  87. ;;
  88. stop)
  89. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  90. do_stop
  91. case "$?" in
  92. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  93. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  94. esac
  95. ;;
  96. status)
  97. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  98. ;;
  99. #reload|force-reload)
  100. #
  101. # If do_reload() is not implemented then leave this commented out
  102. # and leave 'force-reload' as an alias for 'restart'.
  103. #
  104. #log_daemon_msg "Reloading $DESC" "$NAME"
  105. #do_reload
  106. #log_end_msg $?
  107. #;;
  108. restart|force-reload)
  109. #
  110. # If the "reload" option is implemented then remove the
  111. # 'force-reload' alias
  112. #
  113. log_daemon_msg "Restarting $DESC" "$NAME"
  114. do_stop
  115. case "$?" in
  116. 0|1)
  117. do_start
  118. case "$?" in
  119. 0) log_end_msg 0 ;;
  120. 1) log_end_msg 1 ;; # Old process is still running
  121. *) log_end_msg 1 ;; # Failed to start
  122. esac
  123. ;;
  124. *)
  125. # Failed to stop
  126. log_end_msg 1
  127. ;;
  128. esac
  129. ;;
  130. *)
  131. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  132. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  133. exit 3
  134. ;;
  135. esac
  136. :