#!/bin/bash function do_run() { echo "-- run --" if [ ! -n "$p2" ]; then echo "path name error." echo " Usage: ./cli.sh run [profile name] [node id]" return fi if [ ! -n "$p3" ]; then echo "node id error." echo " Usage: ./cli.sh run [profile name] [node id]" return fi echo "run [profile name = $p2, node = $p3]" ./node run -path=./etc/profile/$p2.json -node=$p3 & } function do_stop() { echo "-- stop --" if [ ! -n "$p2" ]; then echo "node id error." echo " Usage: ./cli.sh stop [node id]" return fi echo "stop [node = $p2]" ps x | grep node=$p2 | awk '{print $1}' | xargs kill -15 } function do_show() { echo "-- show --" ps -ef | grep 'path=' | grep 'node=' } function do_version() { echo "-- node version --" ./node version } function do_top() { top -c } function do_log() { echo "-- log --" if [ ! -n "$p2" ]; then echo "error command. Usage: ./cli.sh log game" return fi echo "tail $p2 log" if [ ! -n "$p3" ]; then tail -f "logs/$p2.log" -n 100 else tail -f "logs/$p2.log" -n $p3 fi } function do_kill() { echo "-- kill --" ps x | grep path= | grep node= | awk '{print $1}' | xargs kill -9 } function do_run_all() { echo "-- run $p2 --" if [ ! -n "$p2" ]; then echo "profile name error." echo " Usage: ./cli.sh runall [profile name]" return fi echo "run master node ..." ./node run -path=./etc/profile/$p2.json -node=master-1 & sleep 3 echo "run center node ..." ./node run -path=./etc/profile/$p2.json -node=center-1 & #echo "run cross node ..." #./node run -path=./etc/profile/$p2.json -node=cross-1 & echo "run game node ..." ./node run -path=./etc/profile/$p2.json -node=10001 & echo "run web node ..." ./node run -path=./etc/profile/$p2.json -node=web-1 & echo "run gate node ..." ./node run -path=./etc/profile/$p2.json -node=gate-1 & } function do_stop_all() { echo "-- stop --" ps x | grep path= | grep node= | awk '{print $1}' | xargs kill -15 } echo "----------------NODE CLI------------------" p2=$2 p3=$3 case $1 in run) do_run do_show ;; stop) do_stop sleep 3 do_show ;; kill) do_kill do_show ;; show) do_show ;; log) do_log ;; version) do_version ;; top) do_top ;; runall) do_run_all do_show ;; stopall) do_stop_all do_show ;; *) echo "COMMAND:" echo "" echo " ./cli.sh run [profile name] [node id]" echo " ./cli.sh stop [node id]" echo " ./cli.sh kill" echo " ./cli.sh show" echo " ./cli.sh log [log name] [num]" echo " ./cli.sh version" echo " ./cli.sh top" echo "" echo " ./cli.sh runall [profile name]" echo " ./cli.sh stopall" ;; esac echo "----------------NODE CLI------------------"