cli.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/bin/bash
  2. function do_run() {
  3. echo "-- run --"
  4. if [ ! -n "$p2" ]; then
  5. echo "path name error."
  6. echo " Usage: ./cli.sh run [profile name] [node id]"
  7. return
  8. fi
  9. if [ ! -n "$p3" ]; then
  10. echo "node id error."
  11. echo " Usage: ./cli.sh run [profile name] [node id]"
  12. return
  13. fi
  14. echo "run [profile name = $p2, node = $p3]"
  15. ./node run -path=./etc/profile/$p2.json -node=$p3 &
  16. }
  17. function do_stop() {
  18. echo "-- stop --"
  19. if [ ! -n "$p2" ]; then
  20. echo "node id error."
  21. echo " Usage: ./cli.sh stop [node id]"
  22. return
  23. fi
  24. echo "stop [node = $p2]"
  25. ps x | grep node=$p2 | awk '{print $1}' | xargs kill -15
  26. }
  27. function do_show() {
  28. echo "-- show --"
  29. ps -ef | grep 'path=' | grep 'node='
  30. }
  31. function do_version() {
  32. echo "-- node version --"
  33. ./node version
  34. }
  35. function do_top() {
  36. top -c
  37. }
  38. function do_log() {
  39. echo "-- log --"
  40. if [ ! -n "$p2" ]; then
  41. echo "error command. Usage: ./cli.sh log game"
  42. return
  43. fi
  44. echo "tail $p2 log"
  45. if [ ! -n "$p3" ]; then
  46. tail -f "logs/$p2.log" -n 100
  47. else
  48. tail -f "logs/$p2.log" -n $p3
  49. fi
  50. }
  51. function do_kill() {
  52. echo "-- kill --"
  53. ps x | grep path= | grep node= | awk '{print $1}' | xargs kill -9
  54. }
  55. function do_run_all() {
  56. echo "-- run $p2 --"
  57. if [ ! -n "$p2" ]; then
  58. echo "profile name error."
  59. echo " Usage: ./cli.sh runall [profile name]"
  60. return
  61. fi
  62. echo "run master node ..."
  63. ./node run -path=./etc/profile/$p2.json -node=master-1 &
  64. sleep 3
  65. echo "run center node ..."
  66. ./node run -path=./etc/profile/$p2.json -node=center-1 &
  67. #echo "run cross node ..."
  68. #./node run -path=./etc/profile/$p2.json -node=cross-1 &
  69. echo "run pay node ..."
  70. ./node run -path=./etc/profile/$p2.json -node=pay-1 &
  71. echo "run game node ..."
  72. ./node run -path=./etc/profile/$p2.json -node=10001 &
  73. echo "run web node ..."
  74. ./node run -path=./etc/profile/$p2.json -node=web-1 &
  75. echo "run gate node ..."
  76. ./node run -path=./etc/profile/$p2.json -node=gate-1 &
  77. }
  78. function do_stop_all() {
  79. echo "-- stop --"
  80. ps x | grep path= | grep node= | awk '{print $1}' | xargs kill -15
  81. }
  82. echo "----------------NODE CLI------------------"
  83. p2=$2
  84. p3=$3
  85. case $1 in
  86. run)
  87. do_run
  88. do_show
  89. ;;
  90. stop)
  91. do_stop
  92. sleep 3
  93. do_show
  94. ;;
  95. kill)
  96. do_kill
  97. do_show
  98. ;;
  99. show)
  100. do_show
  101. ;;
  102. log)
  103. do_log
  104. ;;
  105. version)
  106. do_version
  107. ;;
  108. top)
  109. do_top
  110. ;;
  111. runall)
  112. do_run_all
  113. do_show
  114. ;;
  115. stopall)
  116. do_stop_all
  117. do_show
  118. ;;
  119. *)
  120. echo "COMMAND:"
  121. echo ""
  122. echo " ./cli.sh run [profile name] [node id]"
  123. echo " ./cli.sh stop [node id]"
  124. echo " ./cli.sh kill"
  125. echo " ./cli.sh show"
  126. echo " ./cli.sh log [log name] [num]"
  127. echo " ./cli.sh version"
  128. echo " ./cli.sh top"
  129. echo ""
  130. echo " ./cli.sh runall [profile name]"
  131. echo " ./cli.sh stopall"
  132. ;;
  133. esac
  134. echo "----------------NODE CLI------------------"