Loading

/etc/init.d/gogs

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          gogs
  4. # Required-Start:    $syslog $network
  5. # Required-Stop:     $syslog
  6. # Should-Start:      mysql postgresql
  7. # Should-Stop:       mysql postgresql
  8. # Default-Start:     2 3 4 5
  9. # Default-Stop:      0 1 6
  10. # Short-Description: A self-hosted Git service written in Go.
  11. # Description:       A self-hosted Git service written in Go.
  12. ### END INIT INFO
  13.  
  14. # Author: Danny Boisvert
  15.  
  16. # Do NOT "set -e"
  17.  
  18. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  19. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  20. DESC="Gogs"
  21. NAME=gogs
  22. SERVICEVERBOSE=yes
  23. PIDFILE=/var/run/$NAME.pid
  24. SCRIPTNAME=/etc/init.d/$NAME
  25. WORKINGDIR=/home/git/gogs
  26. DAEMON=$WORKINGDIR/$NAME
  27. DAEMON_ARGS="web"
  28. USER=git
  29.  
  30. # Read configuration variable file if it is present
  31. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  32.  
  33. # Exit if the package is not installed
  34. [ -x "$DAEMON" ] || exit 0
  35.  
  36. # Load the VERBOSE setting and other rcS variables
  37. . /lib/init/vars.sh
  38.  
  39. # Define LSB log_* functions.
  40. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  41. # and status_of_proc is working.
  42. . /lib/lsb/init-functions
  43.  
  44. #
  45. # Function that starts the daemon/service
  46. #
  47. do_start()
  48. {
  49.         # Return
  50.         #   0 if daemon has been started
  51.         #   1 if daemon was already running
  52.         #   2 if daemon could not be started
  53.  /bin/sh  -c "USER=$USER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- $DAEMON_ARGS > /dev/null \\
  54.                        --test --chdir $WORKINGDIR --chuid $USER \\
  55.                        || return 1"
  56.  /bin/sh  -c "USER=$USER start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
  57.                        --background --chdir $WORKINGDIR --chuid $USER \\
  58.                        --exec $DAEMON -- $DAEMON_ARGS \\
  59.                        || return 2"
  60. }
  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/1/KILL/5 --pidfile $PIDFILE --name $NAME
  73.         RETVAL="$?"
  74.         [ "$RETVAL" = 2 ] && return 2
  75.         start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON
  76.         [ "$?" = 2 ] && return 2
  77.         # Many daemons don't delete their pidfiles when they exit.
  78.         rm -f $PIDFILE
  79.         return "$RETVAL"
  80. }
  81.  
  82.  
  83. case "$1" in
  84.   start)
  85.         [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  86.         do_start
  87.         case "$?" in
  88.                 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
  89.                 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
  90.         esac
  91.         ;;
  92.   stop)
  93.         [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  94.         do_stop
  95.         case "$?" in
  96.                 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
  97.                 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
  98.         esac
  99.         ;;
  100.   status)
  101.         status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  102.         ;;
  103.   restart|force-reload)
  104.         log_daemon_msg "Restarting $DESC" "$NAME"
  105.         do_stop
  106.         case "$?" in
  107.           0|1)
  108.                 do_start
  109.                 case "$?" in
  110.                         0) log_end_msg 0 ;;
  111.                         1) log_end_msg 1 ;; # Old process is still running
  112.                         *) log_end_msg 1 ;; # Failed to start
  113.                 esac
  114.                 ;;
  115.           *)
  116.                 # Failed to stop
  117.                 log_end_msg 1
  118.                 ;;
  119.                 esac
  120.         ;;
  121.   *)
  122.                 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  123.                 exit 3
  124.                 ;;
  125. esac

Comments