gogs.init 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: gogs
  4. # Required-Start: $remote_fs $syslog
  5. # Required-Stop: $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Gogs git management
  9. # Description: Gogs git management
  10. ### END INIT INFO
  11. # Author: Hein-Pieter van Braam <hp@tmm.cx>
  12. #
  13. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  14. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. DESC="Gogs git management"
  16. NAME=gogs
  17. USER=git
  18. DAEMON=/opt/gogs/gogs
  19. DAEMON_ARGS="web"
  20. PIDFILE=/var/run/$NAME.pid
  21. SCRIPTNAME=/etc/init.d/$NAME
  22. # To work around an issue with /opt/gogs/gogs
  23. export USER
  24. # Exit if the package is not installed
  25. [ -x "$DAEMON" ] || exit 0
  26. # Read configuration variable file if it is present
  27. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  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. start-stop-daemon --background --chuid $USER --chdir /opt/gogs --start --quiet --make-pidfile --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  44. || return 1
  45. start-stop-daemon --background --chuid $USER --chdir /opt/gogs --start --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- \
  46. $DAEMON_ARGS \
  47. || return 2
  48. # Add code here, if necessary, that waits for the process to be ready
  49. # to handle requests from services started subsequently which depend
  50. # on this one. As a last resort, sleep for some time.
  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 --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  63. RETVAL="$?"
  64. [ "$RETVAL" = 2 ] && return 2
  65. # Wait for children to finish too if this is a daemon that forks
  66. # and if the daemon is only ever run from this initscript.
  67. # If the above conditions are not satisfied then add some other code
  68. # that waits for the process to drop all resources that could be
  69. # needed by services started subsequently. A last resort is to
  70. # sleep for some time.
  71. start-stop-daemon --stop --oknodo --retry=0/30/KILL/5 --pidfile $PIDFILE
  72. [ "$?" = 2 ] && return 2
  73. # Many daemons don't delete their pidfiles when they exit.
  74. rm -f $PIDFILE
  75. return "$RETVAL"
  76. }
  77. #
  78. # Function that sends a SIGHUP to the daemon/service
  79. #
  80. do_reload() {
  81. #
  82. # If the daemon can reload its configuration without
  83. # restarting (for example, when it is sent a SIGHUP),
  84. # then implement that here.
  85. #
  86. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  87. return 0
  88. }
  89. case "$1" in
  90. start)
  91. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  92. do_start
  93. case "$?" in
  94. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  95. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  96. esac
  97. ;;
  98. stop)
  99. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  100. do_stop
  101. case "$?" in
  102. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  103. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  104. esac
  105. ;;
  106. status)
  107. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  108. ;;
  109. restart|force-reload)
  110. #
  111. # If the "reload" option is implemented then remove the
  112. # 'force-reload' alias
  113. #
  114. log_daemon_msg "Restarting $DESC" "$NAME"
  115. do_stop
  116. case "$?" in
  117. 0|1)
  118. do_start
  119. case "$?" in
  120. 0) log_end_msg 0 ;;
  121. 1) log_end_msg 1 ;; # Old process is still running
  122. *) log_end_msg 1 ;; # Failed to start
  123. esac
  124. ;;
  125. *)
  126. # Failed to stop
  127. log_end_msg 1
  128. ;;
  129. esac
  130. ;;
  131. *)
  132. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  133. exit 3
  134. ;;
  135. esac
  136. :