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.

124 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 "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
  44. --exec $DAEMON -- $DAEMON_ARGS --test > /dev/null \\
  45. || return 1"
  46. sh -c "start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile \\
  47. --background --exec /bin/su -- - $USER -c \"cd \\\"$WORKINGDIR\\\" && $DAEMON -- $DAEMON_ARGS\" \\
  48. || return 2"
  49. }
  50. #
  51. # Function that stops the daemon/service
  52. #
  53. do_stop()
  54. {
  55. # Return
  56. # 0 if daemon has been stopped
  57. # 1 if daemon was already stopped
  58. # 2 if daemon could not be stopped
  59. # other if a failure occurred
  60. start-stop-daemon --stop --quiet --retry=TERM/1/KILL/5 --pidfile $PIDFILE --name $NAME
  61. RETVAL="$?"
  62. [ "$RETVAL" = 2 ] && return 2
  63. start-stop-daemon --stop --quiet --oknodo --retry=0/1/KILL/5 --exec $DAEMON
  64. [ "$?" = 2 ] && return 2
  65. # Many daemons don't delete their pidfiles when they exit.
  66. rm -f $PIDFILE
  67. return "$RETVAL"
  68. }
  69. case "$1" in
  70. start)
  71. [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  72. do_start
  73. case "$?" in
  74. 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
  75. 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
  76. esac
  77. ;;
  78. stop)
  79. [ "$SERVICEVERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  80. do_stop
  81. case "$?" in
  82. 0|1) [ "$SERVICEVERBOSE" != no ] && log_end_msg 0 ;;
  83. 2) [ "$SERVICEVERBOSE" != no ] && log_end_msg 1 ;;
  84. esac
  85. ;;
  86. status)
  87. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  88. ;;
  89. restart|force-reload)
  90. log_daemon_msg "Restarting $DESC" "$NAME"
  91. do_stop
  92. case "$?" in
  93. 0|1)
  94. do_start
  95. case "$?" in
  96. 0) log_end_msg 0 ;;
  97. 1) log_end_msg 1 ;; # Old process is still running
  98. *) log_end_msg 1 ;; # Failed to start
  99. esac
  100. ;;
  101. *)
  102. # Failed to stop
  103. log_end_msg 1
  104. ;;
  105. esac
  106. ;;
  107. *)
  108. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  109. exit 3
  110. ;;
  111. esac
  112. :