gogs 3.1 KB

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