Sin descripción
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.

etc_init.d_znc 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: znc
  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: ZNC IRC bouncer
  9. # Description: ZNC is an IRC bouncer
  10. ### END INIT INFO
  11. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  12. DESC="ZNC daemon"
  13. NAME=znc
  14. DAEMON=/usr/local/bin/$NAME
  15. DATADIR=/var/lib/znc
  16. DAEMON_ARGS="--datadir=$DATADIR"
  17. PIDDIR=/var/run/znc
  18. PIDFILE=$PIDDIR/$NAME.pid
  19. SCRIPTNAME=/etc/init.d/$NAME
  20. USER=znc
  21. GROUP=znc
  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.2-14) to ensure that this file is present
  30. # and status_of_proc is working.
  31. . /lib/lsb/init-functions
  32. #
  33. # Function that starts the daemon/service
  34. #
  35. do_start()
  36. {
  37. # Return
  38. # 0 if daemon has been started
  39. # 1 if daemon was already running
  40. # 2 if daemon could not be started
  41. if [ ! -d $PIDDIR ]
  42. then
  43. mkdir $PIDDIR
  44. fi
  45. chown $USER:$GROUP $PIDDIR
  46. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test --chuid $USER > /dev/null || return 1
  47. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER -- $DAEMON_ARGS > /dev/null || return 2
  48. }
  49. #
  50. # Function that stops the daemon/service
  51. #
  52. do_stop()
  53. {
  54. # Return
  55. # 0 if daemon has been stopped
  56. # 1 if daemon was already stopped
  57. # 2 if daemon could not be stopped
  58. # other if a failure occurred
  59. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME --chuid $USER
  60. RETVAL="$?"
  61. [ "$RETVAL" = 2 ] && return 2
  62. # Wait for children to finish too if this is a daemon that forks
  63. # and if the daemon is only ever run from this initscript.
  64. # If the above conditions are not satisfied then add some other code
  65. # that waits for the process to drop all resources that could be
  66. # needed by services started subsequently. A last resort is to
  67. # sleep for some time.
  68. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON --chuid $USER
  69. [ "$?" = 2 ] && return 2
  70. # Many daemons don't delete their pidfiles when they exit.
  71. rm -f $PIDFILE
  72. return "$RETVAL"
  73. }
  74. #
  75. # Function that sends a SIGHUP to the daemon/service
  76. #
  77. do_reload() {
  78. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME --chuid $USER
  79. return 0
  80. }
  81. case "$1" in
  82. start)
  83. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  84. do_start
  85. case "$?" in
  86. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  87. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  88. esac
  89. ;;
  90. stop)
  91. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  92. do_stop
  93. case "$?" in
  94. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  95. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  96. esac
  97. ;;
  98. status)
  99. status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
  100. ;;
  101. reload)
  102. log_daemon_msg "Reloading $DESC" "$NAME"
  103. do_reload
  104. log_end_msg $?
  105. ;;
  106. restart)
  107. log_daemon_msg "Restarting $DESC" "$NAME"
  108. do_stop
  109. case "$?" in
  110. 0|1)
  111. do_start
  112. case "$?" in
  113. 0) log_end_msg 0 ;;
  114. 1) log_end_msg 1 ;; # Old process is still running
  115. *) log_end_msg 1 ;; # Failed to start
  116. esac
  117. ;;
  118. *)
  119. # Failed to stop
  120. log_end_msg 1
  121. ;;
  122. esac
  123. ;;
  124. *)
  125. echo "Usage: $SCRIPTNAME {status|start|stop|reload|restart}" >&2
  126. exit 3
  127. ;;
  128. esac
  129. :