gogs.init 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. # We use a newer version of go now
  25. LD_LIBRARY_PATH=/opt/gcc-5.1.0
  26. export LD_LIBRARY_PATH
  27. # Exit if the package is not installed
  28. [ -x "$DAEMON" ] || exit 0
  29. # Read configuration variable file if it is present
  30. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  31. # Load the VERBOSE setting and other rcS variables
  32. . /lib/init/vars.sh
  33. # Define LSB log_* functions.
  34. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  35. # and status_of_proc is working.
  36. . /lib/lsb/init-functions
  37. #
  38. # Function that starts the daemon/service
  39. #
  40. do_start()
  41. {
  42. # Return
  43. # 0 if daemon has been started
  44. # 1 if daemon was already running
  45. # 2 if daemon could not be started
  46. start-stop-daemon --background --chuid $USER --chdir /opt/gogs --start --quiet --make-pidfile --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  47. || return 1
  48. start-stop-daemon --background --chuid $USER --chdir /opt/gogs --start --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- \
  49. $DAEMON_ARGS \
  50. || return 2
  51. # Add code here, if necessary, that waits for the process to be ready
  52. # to handle requests from services started subsequently which depend
  53. # on this one. As a last resort, sleep for some time.
  54. }
  55. #
  56. # Function that stops the daemon/service
  57. #
  58. do_stop()
  59. {
  60. # Return
  61. # 0 if daemon has been stopped
  62. # 1 if daemon was already stopped
  63. # 2 if daemon could not be stopped
  64. # other if a failure occurred
  65. start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  66. RETVAL="$?"
  67. [ "$RETVAL" = 2 ] && return 2
  68. # Wait for children to finish too if this is a daemon that forks
  69. # and if the daemon is only ever run from this initscript.
  70. # If the above conditions are not satisfied then add some other code
  71. # that waits for the process to drop all resources that could be
  72. # needed by services started subsequently. A last resort is to
  73. # sleep for some time.
  74. start-stop-daemon --stop --oknodo --retry=0/30/KILL/5 --pidfile $PIDFILE
  75. [ "$?" = 2 ] && return 2
  76. # Many daemons don't delete their pidfiles when they exit.
  77. rm -f $PIDFILE
  78. return "$RETVAL"
  79. }
  80. #
  81. # Function that sends a SIGHUP to the daemon/service
  82. #
  83. do_reload() {
  84. #
  85. # If the daemon can reload its configuration without
  86. # restarting (for example, when it is sent a SIGHUP),
  87. # then implement that here.
  88. #
  89. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  90. return 0
  91. }
  92. case "$1" in
  93. start)
  94. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  95. do_start
  96. case "$?" in
  97. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  98. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  99. esac
  100. ;;
  101. stop)
  102. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  103. do_stop
  104. case "$?" in
  105. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  106. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  107. esac
  108. ;;
  109. status)
  110. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  111. ;;
  112. restart|force-reload)
  113. #
  114. # If the "reload" option is implemented then remove the
  115. # 'force-reload' alias
  116. #
  117. log_daemon_msg "Restarting $DESC" "$NAME"
  118. do_stop
  119. case "$?" in
  120. 0|1)
  121. do_start
  122. case "$?" in
  123. 0) log_end_msg 0 ;;
  124. 1) log_end_msg 1 ;; # Old process is still running
  125. *) log_end_msg 1 ;; # Failed to start
  126. esac
  127. ;;
  128. *)
  129. # Failed to stop
  130. log_end_msg 1
  131. ;;
  132. esac
  133. ;;
  134. *)
  135. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  136. exit 3
  137. ;;
  138. esac
  139. :