Advertisement
Lekensteyn

svnserve initscript

Feb 19th, 2012
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.89 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          svnserve
  4. # Required-Start:    $network $remote_fs $syslog
  5. # Required-Stop:     $network $remote_fs $syslog
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Start/stop Subversion server
  9. ### END INIT INFO
  10.  
  11. # Author: Lekensteyn <lekensteyn@gmail.com>
  12. #
  13.  
  14. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  15. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  16. DESC="Subversion server"
  17. NAME=svnserve
  18. DAEMON=/usr/bin/svnserve
  19. DAEMON_ARGS="-d --root=/home/svn --threads"
  20. SCRIPTNAME=/etc/init.d/$NAME
  21. UMASK=027
  22. SVNSERVE_USER=svn
  23.  
  24. # Exit if the package is not installed
  25. [ -x "$DAEMON" ] || exit 0
  26.  
  27. # Read configuration variable file if it is present
  28. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  29.  
  30. # Load the VERBOSE setting and other rcS variables
  31. . /lib/init/vars.sh
  32. VERBOSE=yes
  33. # Define LSB log_* functions.
  34. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  35. # and status_of_proc is working.
  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.     pidof "$DAEMON" >/dev/null && return 1
  48.     start-stop-daemon --start --quiet --exec $DAEMON --chuid $SVNSERVE_USER --umask $UMASK -- \
  49.         $DAEMON_ARGS \
  50.         || return 2
  51. }
  52.  
  53. #
  54. # Function that stops the daemon/service
  55. #
  56. do_stop()
  57. {
  58.     # Return
  59.     #   0 if daemon has been stopped
  60.     #   1 if daemon was already stopped
  61.     #   2 if daemon could not be stopped
  62.     #   other if a failure occurred
  63.     start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --exec $DAEMON --user $SVNSERVE_USER
  64.     RETVAL="$?"
  65.     [ "$RETVAL" = 2 ] && return 2
  66.     return "$RETVAL"
  67. }
  68.  
  69. case "$1" in
  70.   start)
  71.     [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  72.     do_start
  73.     case "$?" in
  74.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  75.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  76.     esac
  77.     ;;
  78.   stop)
  79.     [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  80.     do_stop
  81.     case "$?" in
  82.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  83.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  84.     esac
  85.     ;;
  86.   status)
  87.        if pidof "$DAEMON" >/dev/null; then
  88.            log_success_msg "$NAME is running"
  89.        else
  90.            log_failure_msg "$NAME is not running"
  91.            exit 1
  92.        fi
  93.        ;;
  94.   restart|force-reload)
  95.     #
  96.     # If the "reload" option is implemented then remove the
  97.     # 'force-reload' alias
  98.     #
  99.     log_daemon_msg "Restarting $DESC" "$NAME"
  100.     do_stop
  101.     case "$?" in
  102.       0|1)
  103.         do_start
  104.         case "$?" in
  105.             0) log_end_msg 0 ;;
  106.             1) log_end_msg 1 ;; # Old process is still running
  107.             *) log_end_msg 1 ;; # Failed to start
  108.         esac
  109.         ;;
  110.       *)
  111.         # Failed to stop
  112.         log_end_msg 1
  113.         ;;
  114.     esac
  115.     ;;
  116.   *)
  117.     echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  118.     exit 3
  119.     ;;
  120. esac
  121.  
  122. :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement