You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

control 3.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #!/bin/bash
  2. # release version
  3. version=4.0.0
  4. CWD=$(cd $(dirname $0)/; pwd)
  5. cd $CWD
  6. usage()
  7. {
  8. echo $"Usage: $0 {start|stop|restart|status|build|build_local|pack} <module>"
  9. exit 0
  10. }
  11. start_all()
  12. {
  13. test -x n9e-server && start server
  14. test -x n9e-agentd && start agentd
  15. test -x n9e-prober && start prober
  16. }
  17. start()
  18. {
  19. mod=$1
  20. if [ "x${mod}" = "x" ]; then
  21. usage
  22. return
  23. fi
  24. if [ "x${mod}" = "xall" ]; then
  25. start_all
  26. return
  27. fi
  28. binfile=n9e-${mod}
  29. if [ ! -f $binfile ]; then
  30. echo "file[$binfile] not found"
  31. exit 1
  32. fi
  33. if [ $(ps aux|grep -v grep|grep -v control|grep "$binfile" -c) -gt 0 ]; then
  34. echo "${mod} already started"
  35. return
  36. fi
  37. mkdir -p logs/$mod
  38. nohup $CWD/$binfile &> logs/${mod}/stdout.log &
  39. for((i=1;i<=15;i++)); do
  40. if [ $(ps aux|grep -v grep|grep -v control|grep "$binfile" -c) -gt 0 ]; then
  41. echo "${mod} started"
  42. return
  43. fi
  44. sleep 0.2
  45. done
  46. echo "cannot start ${mod}"
  47. exit 1
  48. }
  49. stop_all()
  50. {
  51. test -x n9e-server && stop server
  52. test -x n9e-prober && stop prober
  53. test -x n9e-agentd && stop agentd
  54. }
  55. stop()
  56. {
  57. mod=$1
  58. if [ "x${mod}" = "x" ]; then
  59. usage
  60. return
  61. fi
  62. if [ "x${mod}" = "xall" ]; then
  63. stop_all
  64. return
  65. fi
  66. binfile=n9e-${mod}
  67. if [ $(ps aux|grep -v grep|grep -v control|grep "$binfile" -c) -eq 0 ]; then
  68. echo "${mod} already stopped"
  69. return
  70. fi
  71. ps aux|grep -v grep|grep -v control|grep "$binfile"|awk '{print $2}'|xargs kill
  72. for((i=1;i<=15;i++)); do
  73. if [ $(ps aux|grep -v grep|grep -v control|grep "$binfile" -c) -eq 0 ]; then
  74. echo "${mod} stopped"
  75. return
  76. fi
  77. sleep 0.2
  78. done
  79. echo "cannot stop $mod"
  80. exit 1
  81. }
  82. restart()
  83. {
  84. mod=$1
  85. if [ "x${mod}" = "x" ]; then
  86. usage
  87. return
  88. fi
  89. if [ "x${mod}" = "xall" ]; then
  90. stop_all
  91. start_all
  92. return
  93. fi
  94. stop $mod
  95. start $mod
  96. status
  97. }
  98. status()
  99. {
  100. ps aux|grep -v grep|grep "n9e"
  101. }
  102. build_one()
  103. {
  104. mod=$1
  105. echo -n "building ${mod} ... "
  106. go build -ldflags "-X main.version=${version}" -o n9e-${mod} src/modules/${mod}/${mod}.go
  107. echo "done"
  108. }
  109. build_local_one()
  110. {
  111. mod=$1
  112. echo -n "building ${mod} ... "
  113. go build -mod=vendor -ldflags "-X main.version=${version}" -o n9e-${mod} src/modules/${mod}/${mod}.go
  114. echo "done"
  115. }
  116. build()
  117. {
  118. export GO111MODULE=on
  119. mod=$1
  120. if [ "x${mod}" = "x" ]; then
  121. build_one server
  122. build_one agentd
  123. build_one prober
  124. return
  125. fi
  126. build_one $mod
  127. }
  128. build_local()
  129. {
  130. export GO111MODULE=on
  131. mod=$1
  132. if [ "x${mod}" = "x" ]; then
  133. build_local_one server
  134. build_local_one agentd
  135. build_local_one prober
  136. return
  137. fi
  138. build_local_one $mod
  139. }
  140. reload()
  141. {
  142. mod=$1
  143. if [ "x${mod}" = "x" ]; then
  144. echo "arg: <mod> is necessary"
  145. return
  146. fi
  147. build_one $mod
  148. restart $mod
  149. }
  150. pack()
  151. {
  152. clock=$(date +%s)
  153. mkdir -p ~/n9e.bak.$clock
  154. if ls etc/*.local.yml &>/dev/null; then
  155. mv etc/*.local.yml ~/n9e.bak.$clock
  156. fi
  157. tar zcvf n9e-${version}.tar.gz script control sql etc n9e-*
  158. if ls ~/n9e.bak.$clock/*.local.yml &>/dev/null; then
  159. mv ~/n9e.bak.$clock/*.local.yml etc/
  160. fi
  161. rm -rf ~/n9e.bak.$clock
  162. }
  163. exec()
  164. {
  165. params=${@:2}
  166. if [ ${#2} -gt 0 ]; then
  167. for param in $params
  168. do
  169. $1 $param
  170. if [ "x${mod}" = "xall" ]; then
  171. break
  172. fi
  173. done
  174. else
  175. echo "todo $1 at "$(date "+%Y-%m-%d %H:%M:%S")
  176. $1
  177. echo "done $1 at "$(date "+%Y-%m-%d %H:%M:%S")
  178. fi
  179. }
  180. case "$1" in
  181. start)
  182. exec start ${@:2}
  183. ;;
  184. stop)
  185. exec stop ${@:2}
  186. ;;
  187. restart)
  188. exec restart ${@:2}
  189. ;;
  190. status)
  191. status
  192. ;;
  193. build)
  194. exec build ${@:2}
  195. ;;
  196. build_local)
  197. exec build_local ${@:2}
  198. ;;
  199. reload)
  200. exec reload ${@:2}
  201. ;;
  202. pack)
  203. exec pack ${@:2}
  204. ;;
  205. *)
  206. usage
  207. esac