gogs 2.7 KB

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