ngircd.init 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: ngircd
  4. # Required-Start: $network $local_fs $remote_fs
  5. # Required-Stop: $network $local_fs $remote_fs
  6. # Should-Start: $named $syslog
  7. # Should-Stop: $named $syslog
  8. # Default-Start: 2 3 4 5
  9. # Default-Stop: 0 1 6
  10. # Short-Description: Next generation IRC daemon
  11. # Description: Simple IRC daemon written from scratch
  12. ### END INIT INFO
  13. # Author: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
  14. # Do NOT "set -e"
  15. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  16. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  17. DESC='Next generation IRC daemon'
  18. NAME='ngircd'
  19. DAEMON="/usr/sbin/$NAME"
  20. DAEMON_ARGS=""
  21. PIDDIR='/var/run/ngircd'
  22. PIDFILE="$PIDDIR/$NAME.pid"
  23. SCRIPTNAME="/etc/init.d/$NAME"
  24. DAEMONUSER='irc' # also group
  25. # Exit if the package is not installed
  26. [ -x "$DAEMON" ] || exit 0
  27. # Read configuration variable file if it is present
  28. [ -r "/etc/default/$NAME" ] && . "/etc/default/$NAME"
  29. # Load the VERBOSE setting and other rcS variables
  30. . /lib/init/vars.sh
  31. # Define LSB log_* functions.
  32. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  33. # and status_of_proc is working.
  34. . /lib/lsb/init-functions
  35. # Assert PIDDIR
  36. [ ! -d "$PIDDIR" ] || mkdir -p "$PIDDIR"
  37. chown "$DAEMONUSER:$DAEMONUSER" "$PIDDIR"
  38. # Assert DAEMONUSER's home
  39. DAEMONHOME=$(getent passwd "$DAEMONUSER" | cut -d: -f6)
  40. [ -d "$DAEMONHOME" ] || mkdir -p "$DAEMONHOME"
  41. chown "$DAEMONUSER:$DAEMONUSER" "$DAEMONHOME"
  42. #
  43. # Function that starts the daemon/service
  44. #
  45. do_start()
  46. {
  47. # Return
  48. # 0 if daemon has been started
  49. # 1 if daemon was already running
  50. # 2 if daemon could not be started
  51. start-stop-daemon --start --quiet \
  52. --pidfile "$PIDFILE" --exec "$DAEMON" \
  53. --test > /dev/null || return 1
  54. start-stop-daemon --start --quiet \
  55. --pidfile "$PIDFILE" --exec "$DAEMON" -- \
  56. $DAEMON_ARGS || return 2
  57. # Add code here, if necessary, that waits for the process to be ready
  58. # to handle requests from services started subsequently which depend
  59. # on this one. As a last resort, sleep for some time.
  60. }
  61. #
  62. # Function that stops the daemon/service
  63. #
  64. do_stop()
  65. {
  66. # Return
  67. # 0 if daemon has been stopped
  68. # 1 if daemon was already stopped
  69. # 2 if daemon could not be stopped
  70. # other if a failure occurred
  71. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
  72. --pidfile "$PIDFILE" --name "$NAME"
  73. RETVAL="$?"
  74. [ "$RETVAL" = 2 ] && return 2
  75. # Wait for children to finish too if this is a daemon that forks
  76. # and if the daemon is only ever run from this initscript.
  77. # If the above conditions are not satisfied then add some other code
  78. # that waits for the process to drop all resources that could be
  79. # needed by services started subsequently. A last resort is to
  80. # sleep for some time.
  81. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 \
  82. --exec "$DAEMON"
  83. [ "$?" = 2 ] && return 2
  84. # Many daemons don't delete their pidfiles when they exit.
  85. rm -f "$PIDFILE"
  86. return "$RETVAL"
  87. }
  88. #
  89. # Function that sends a SIGHUP to the daemon/service
  90. #
  91. do_reload() {
  92. start-stop-daemon --stop --signal 1 --quiet \
  93. --pidfile "$PIDFILE" --name "$NAME"
  94. return 0
  95. }
  96. case "$1" in
  97. start)
  98. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  99. do_start
  100. case "$?" in
  101. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  102. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  103. esac
  104. ;;
  105. stop)
  106. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  107. do_stop
  108. case "$?" in
  109. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  110. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  111. esac
  112. ;;
  113. status)
  114. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  115. ;;
  116. reload|force-reload)
  117. log_daemon_msg "Reloading $DESC" "$NAME"
  118. do_reload
  119. log_end_msg $?
  120. ;;
  121. restart)
  122. log_daemon_msg "Restarting $DESC" "$NAME"
  123. do_stop
  124. case "$?" in
  125. 0|1)
  126. do_start
  127. case "$?" in
  128. 0) log_end_msg 0 ;;
  129. 1) log_end_msg 1 ;; # Old process is still running
  130. *) log_end_msg 1 ;; # Failed to start
  131. esac
  132. ;;
  133. *)
  134. # Failed to stop
  135. log_end_msg 1
  136. ;;
  137. esac
  138. ;;
  139. *)
  140. echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  141. exit 3
  142. ;;
  143. esac
  144. exit 0