1
0

ngircd.init 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. --chuid "$DAEMONUSER:$DAEMONUSER" \
  56. --pidfile "$PIDFILE" --exec "$DAEMON" -- \
  57. $DAEMON_ARGS || return 2
  58. # Add code here, if necessary, that waits for the process to be ready
  59. # to handle requests from services started subsequently which depend
  60. # on this one. As a last resort, sleep for some time.
  61. }
  62. #
  63. # Function that stops the daemon/service
  64. #
  65. do_stop()
  66. {
  67. # Return
  68. # 0 if daemon has been stopped
  69. # 1 if daemon was already stopped
  70. # 2 if daemon could not be stopped
  71. # other if a failure occurred
  72. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
  73. --pidfile "$PIDFILE" --name "$NAME"
  74. RETVAL="$?"
  75. [ "$RETVAL" = 2 ] && return 2
  76. # Wait for children to finish too if this is a daemon that forks
  77. # and if the daemon is only ever run from this initscript.
  78. # If the above conditions are not satisfied then add some other code
  79. # that waits for the process to drop all resources that could be
  80. # needed by services started subsequently. A last resort is to
  81. # sleep for some time.
  82. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 \
  83. --exec "$DAEMON"
  84. [ "$?" = 2 ] && return 2
  85. # Many daemons don't delete their pidfiles when they exit.
  86. rm -f "$PIDFILE"
  87. return "$RETVAL"
  88. }
  89. #
  90. # Function that sends a SIGHUP to the daemon/service
  91. #
  92. do_reload() {
  93. start-stop-daemon --stop --signal 1 --quiet \
  94. --pidfile "$PIDFILE" --name "$NAME"
  95. return 0
  96. }
  97. case "$1" in
  98. start)
  99. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  100. do_start
  101. case "$?" in
  102. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  103. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  104. esac
  105. ;;
  106. stop)
  107. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  108. do_stop
  109. case "$?" in
  110. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  111. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  112. esac
  113. ;;
  114. status)
  115. status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
  116. ;;
  117. reload|force-reload)
  118. log_daemon_msg "Reloading $DESC" "$NAME"
  119. do_reload
  120. log_end_msg $?
  121. ;;
  122. restart)
  123. log_daemon_msg "Restarting $DESC" "$NAME"
  124. do_stop
  125. case "$?" in
  126. 0|1)
  127. do_start
  128. case "$?" in
  129. 0) log_end_msg 0 ;;
  130. 1) log_end_msg 1 ;; # Old process is still running
  131. *) log_end_msg 1 ;; # Failed to start
  132. esac
  133. ;;
  134. *)
  135. # Failed to stop
  136. log_end_msg 1
  137. ;;
  138. esac
  139. ;;
  140. *)
  141. echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2
  142. exit 3
  143. ;;
  144. esac
  145. exit 0