gogs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/sh
  2. #
  3. # /etc/init.d/gogs
  4. #
  5. # Runs the Gogs Go Git Service.
  6. #
  7. ### BEGIN INIT INFO
  8. # Provides: gogs
  9. # Required-Start: $remote_fs
  10. # Required-Stop: $remote_fs
  11. # Default-Start: 2 3 4 5
  12. # Default-Stop: 0 1 6
  13. # Short-Description: Start gogs at boot time.
  14. # Description: Control gogs.
  15. ### END INIT INFO
  16. # Default values
  17. NAME=gogs
  18. GOGS_HOME=/home/git/gogs
  19. GOGS_PATH=${GOGS_HOME}/$NAME
  20. GOGS_USER=git
  21. SERVICENAME="Go Git Service"
  22. LOCKFILE=/var/lock/subsys/gogs
  23. LOGPATH=${GOGS_HOME}/log
  24. LOGFILE=${LOGPATH}/error.log
  25. # gogs creates its own gogs.log from stdout
  26. RETVAL=0
  27. # Read configuration from /etc/sysconfig/gogs to override defaults
  28. [ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
  29. # Don't do anything if nothing is installed
  30. test -x ${GOGS_PATH} || { echo "$NAME not installed";
  31. if [ "$1" = "stop" ]; then exit 0;
  32. else exit 5; fi; }
  33. # exit if logpath dir is not created.
  34. test -r ${LOGPATH} || { echo "$LOGPATH not existing";
  35. if [ "$1" = "stop" ]; then exit 0;
  36. else exit 6; fi; }
  37. # Source function library.
  38. . /etc/rc.status
  39. # Reset status of this service
  40. rc_reset
  41. case "$1" in
  42. start)
  43. echo -n "Starting ${SERVICENAME} "
  44. # As we can't use startproc, we have to check ourselves if the service is already running
  45. /sbin/checkproc ${GOGS_PATH}
  46. if [ $? -eq 0 ]; then
  47. # return skipped as service is already running
  48. (exit 5)
  49. else
  50. su - ${GOGS_USER} -c "USER=${GOGS_USER} ${GOGS_PATH} web 2>&1 >>${LOGFILE} &"
  51. fi
  52. # Remember status and be verbose
  53. rc_status -v
  54. ;;
  55. stop)
  56. echo -n "Shutting down ${SERVICENAME} "
  57. ## Stop daemon with killproc(8) and if this fails
  58. ## killproc sets the return value according to LSB.
  59. /sbin/killproc ${GOGS_PATH}
  60. # Remember status and be verbose
  61. rc_status -v
  62. ;;
  63. restart)
  64. ## Stop the service and regardless of whether it was
  65. ## running or not, start it again.
  66. $0 stop
  67. $0 start
  68. # Remember status and be quiet
  69. rc_status
  70. ;;
  71. status)
  72. echo -n "Checking for ${SERVICENAME} "
  73. ## Check status with checkproc(8), if process is running
  74. ## checkproc will return with exit status 0.
  75. # Return value is slightly different for the status command:
  76. # 0 - service up and running
  77. # 1 - service dead, but /var/run/ pid file exists
  78. # 2 - service dead, but /var/lock/ lock file exists
  79. # 3 - service not running (unused)
  80. # 4 - service status unknown :-(
  81. # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
  82. # NOTE: checkproc returns LSB compliant status values.
  83. /sbin/checkproc ${GOGS_PATH}
  84. # NOTE: rc_status knows that we called this init script with
  85. # "status" option and adapts its messages accordingly.
  86. rc_status -v
  87. ;;
  88. *)
  89. echo "Usage: $0 {start|stop|status|restart}"
  90. exit 1
  91. ;;
  92. esac
  93. rc_exit