S801gogs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/sh
  2. ### Custom user script for gogs
  3. ### First param is:
  4. ### "start" (call at start entware),
  5. ### "stop" (call before stop entware),
  6. ###
  7. ### Note the additional requirements for gogs on ddwrt: shadow user, group, sudo, daemonize
  8. PIDFILE="/opt/var/run/gogs.pid"
  9. USER="gogs"
  10. GOROOT="/opt/bin/go"
  11. GOPATH="/opt/go"
  12. ENABLED=yes
  13. PROC="gogs"
  14. DESC=$PROC
  15. PREARGS="/opt/bin/sudo -u $USER /opt/bin/daemonize"
  16. GOGSBIN="$GOPATH/src/github.com/gogs/gogs/gogs"
  17. ARGS="web"
  18. ansi_red="\033[1;31m";
  19. ansi_white="\033[1;37m";
  20. ansi_green="\033[1;32m";
  21. ansi_yellow="\033[1;33m";
  22. ansi_blue="\033[1;34m";
  23. ansi_bell="\007";
  24. ansi_blink="\033[5m";
  25. ansi_std="\033[m";
  26. ansi_rev="\033[7m";
  27. ansi_ul="\033[4m";
  28. case "$1" in
  29. start)
  30. # start gogs web
  31. if [ -f "$PIDFILE" ]
  32. then
  33. echo "$DESC is already running ...`pidof $PROC`"
  34. else
  35. echo -e -n "$ansi_white Starting $DESC... $ansi_std"
  36. export GOROOT=$GOROOT
  37. export GOPATH=$GOPATH
  38. export PATH=$PATH:$GOROOT/bin
  39. $PREARGS $GOGSBIN $ARGS > /dev/null 2>&1 &
  40. COUNTER=0
  41. LIMIT=10
  42. while [ -z "`pidof $PROC`" -a "$COUNTER" -le "$LIMIT" ]; do
  43. sleep 1;
  44. COUNTER=`expr $COUNTER + 1`
  45. done
  46. if [ -z "`pidof $PROC`" ]
  47. then
  48. echo -e " $ansi_red failed. $ansi_std"
  49. logger "Failed to start $DESC from $CALLER."
  50. return 255
  51. else
  52. echo -e " $ansi_green done. $ansi_std"
  53. logger "Started $DESC from $CALLER."
  54. echo `pidof $PROC` > "$PIDFILE"
  55. return 0
  56. fi
  57. fi
  58. ;;
  59. stop)
  60. echo -e -n "$ansi_white Shutting down $PROC... $ansi_std"
  61. killall $PROC 2>/dev/null
  62. if [ -f "$PIDFILE" ]
  63. then
  64. rm "$PIDFILE"
  65. fi
  66. COUNTER=0
  67. LIMIT=10
  68. while [ -n "`pidof $PROC`" -a "$COUNTER" -le "$LIMIT" ]; do
  69. sleep 1;
  70. COUNTER=`expr $COUNTER + 1`
  71. done
  72. ;;
  73. kill)
  74. echo -e -n "$ansi_white Killing $PROC... $ansi_std"
  75. killall -9 $PROC 2>/dev/null
  76. ;;
  77. status | check)
  78. echo -e -n "$ansi_white Checking $DESC... "
  79. if [ -n "`pidof $PROC`" ]
  80. then
  81. echo -e " $ansi_green alive. $ansi_std";
  82. return 0
  83. else
  84. echo -e " $ansi_red dead. $ansi_std";
  85. return 1
  86. fi
  87. ;;
  88. *)
  89. echo "Usage: $0 {start|stop|status}"
  90. exit 1
  91. ;;
  92. esac