deploy-ssh-server.sh 2.3 KB

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