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.

126 lines
3.0 KiB

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