api-gateway.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. #time=`date +%Y-%m-%d.%H-%M`
  3. #set -x
  4. set -e
  5. dirPath=~/deploy/yxt-api-gateway
  6. serverName=yxt_api_gateway
  7. logPath=/data/logs/soap_gateway_test/soap_gateway_test.log
  8. cmd=$1
  9. profiles=${2:-"test"}
  10. echoPrefix="\033[36m+"
  11. echoSuffix="\033[0m"
  12. #-------------------------------------------------------------------
  13. JAVA_MEM_OPTS=" -DappName=${serverName} -server -Xmx4g -Xms4g"
  14. DATABASE_OPTS=" -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false"
  15. JAVA_OPTS_EXT=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai"
  16. #-------------------------------------------------------------------
  17. startServer() {
  18. pid=$1
  19. if [ -z $pid ];then
  20. echo -e "$echoPrefix cd $dirPath $echoSuffix"
  21. cd $dirPath
  22. echo -e "$echoPrefix java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./soap-gateway-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=9000 >>/dev/null 2>&1 & $echoSuffix"
  23. java $JAVA_MEM_OPTS $DATABASE_OPTS $JAVA_OPTS_EXT -jar ./soap-gateway-0.0.0-SNAPSHOT.jar --spring.profiles.active=global,$profiles --server.port=9000 >>/dev/null 2>&1 &
  24. echo "$serverName 启动成功!"
  25. else
  26. echo "$serverName 正在运行..."
  27. fi
  28. echo "查看日志: tail -F $logPath -n 100"
  29. }
  30. stopServer() {
  31. pid=$1
  32. if [ -z $pid ];then
  33. echo "$serverName 未运行"
  34. else
  35. echo -e "$echoPrefix ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print \$2}' | xargs kill $echoSuffix"
  36. ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}' | xargs kill
  37. echo "$serverName 已停止!"
  38. fi
  39. }
  40. deployServer() {
  41. pid=$1
  42. if [ ! -z $pid ];then
  43. stopServer $pid
  44. sleep 3s
  45. fi
  46. startServer
  47. }
  48. logs() {
  49. tail -F $logPath -n 100
  50. }
  51. pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`
  52. # 操作参数: restart start stop kill log logs
  53. if [ "$cmd" == "restart" ];then
  54. deployServer $pid
  55. elif [ "$cmd" == "start" ];then
  56. startServer $pid
  57. elif [ "$cmd" == "stop" ] || [ "$cmd" == "kill" ];then
  58. stopServer $pid
  59. elif [ "$cmd" == "log" ] || [ "$cmd" == "logs" ];then
  60. logs
  61. else
  62. if [ -z $pid ];then
  63. echo "$serverName 未运行 | 输入操作参数: restart start stop kill log logs"
  64. else
  65. echo "输入操作参数: restart start stop kill log logs"
  66. echo "pid=$pid | $serverName 正在运行... | 查看日志: tail -F $logPath -n 100"
  67. fi
  68. fi
  69. # bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/yxt/api-gateway.sh) [cmd profiles]