Advertisement
Guest User

lighttpd init script

a guest
Aug 4th, 2010
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.48 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          lighttpd
  4. # Required-Start:    $local_fs $network
  5. # Required-Stop:     $local_fs $network
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: lighttpd
  9. # Description:       The lighttpd web server
  10. ### END INIT INFO
  11.  
  12. # Author: W. Babernits <wbabernits[at]onext[dot]de>
  13. #
  14.  
  15. PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
  16. DESC="lighttpd web server"
  17. NAME=lighttpd
  18. DAEMON=/usr/local/sbin/$NAME
  19. CONFIG_FILE=/usr/local/etc/lighttpd/lighttpd.conf
  20. DAEMON_ARGS="-f $CONFIG_FILE"
  21. PIDFILE=/var/run/$NAME.pid
  22. SCRIPTNAME=/etc/init.d/$NAME
  23. VERBOSE="yes"
  24.  
  25. # Exit if the package is not installed
  26. [ -x "$DAEMON" ] || exit 0
  27.  
  28. # Read configuration variable file if it is present
  29. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  30.  
  31. # Load the VERBOSE setting and other rcS variables
  32. . /lib/init/vars.sh
  33.  
  34. # Define LSB log_* functions.
  35. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  36. . /lib/lsb/init-functions
  37.  
  38. #
  39. # Function that starts the daemon/service
  40. #
  41. do_start()
  42. {
  43.     # Return
  44.     #   0 if daemon has been started
  45.     #   1 if daemon was already running
  46.     #   2 if daemon could not be started
  47.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  48.         || return 1
  49.     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  50.         $DAEMON_ARGS \
  51.         || return 2
  52. }
  53.  
  54. #
  55. # Function that stops the daemon/service
  56. #
  57. do_stop()
  58. {
  59.     # Return
  60.     #   0 if daemon has been stopped
  61.     #   1 if daemon was already stopped
  62.     #   2 if daemon could not be stopped
  63.     #   other if a failure occurred
  64.     start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  65.     RETVAL="$?"
  66.     [ "$RETVAL" = 2 ] && return 2
  67.     # Wait for children to finish too if this is a daemon that forks
  68.     # and if the daemon is only ever run from this initscript.
  69.     start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  70.     [ "$?" = 2 ] && return 2
  71.     # Many daemons don't delete their pidfiles when they exit.
  72.     rm -f $PIDFILE
  73.     return "$RETVAL"
  74. }
  75.  
  76. #
  77. # Function that sends a SIGHUP to the daemon/service
  78. #
  79. do_reload() {
  80.     #
  81.     # If the daemon can reload its configuration without
  82.     # restarting (for example, when it is sent a SIGHUP),
  83.     # then implement that here.
  84.     #
  85.     start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  86.     return 0
  87. }
  88.  
  89. case "$1" in
  90.   start)
  91.     log_daemon_msg "Starting $DESC" "$NAME"
  92.     do_start
  93.     case "$?" in
  94.         0|1) log_end_msg 0 ;;
  95.         2) log_end_msg 1 ;;
  96.     esac
  97.     ;;
  98.   stop)
  99.     log_daemon_msg "Stopping $DESC" "$NAME"
  100.     do_stop
  101.     case "$?" in
  102.         0|1) log_end_msg 0 ;;
  103.         2) log_end_msg 1 ;;
  104.     esac
  105.     ;;
  106.   #reload|force-reload)
  107.     #
  108.     # If do_reload() is not implemented then leave this commented out
  109.     # and leave 'force-reload' as an alias for 'restart'.
  110.     #
  111.     #log_daemon_msg "Reloading $DESC" "$NAME"
  112.     #do_reload
  113.     #log_end_msg $?
  114.     #;;
  115.   restart|force-reload)
  116.     #
  117.     # If the "reload" option is implemented then remove the
  118.     # 'force-reload' alias
  119.     #
  120.     log_daemon_msg "Restarting $DESC" "$NAME"
  121.     do_stop
  122.     case "$?" in
  123.       0|1)
  124.         do_start
  125.         case "$?" in
  126.             0) log_end_msg 0 ;;
  127.             1) log_end_msg 1 ;; # Old process is still running
  128.             *) log_end_msg 1 ;; # Failed to start
  129.         esac
  130.         ;;
  131.       *)
  132.         # Failed to stop
  133.         log_end_msg 1
  134.         ;;
  135.     esac
  136.     ;;
  137.   *)
  138.     #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  139.     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  140.     exit 3
  141.     ;;
  142. esac
  143.  
  144. :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement