sh_web_app_2006_Svr.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. echo "entry..."
  3. # 定义变量
  4. # 要运行的jar包路径,加不加引号都行。 注意:等号两边 不能 有空格,否则会提示command找不到
  5. APP_NAME=web_app_2006.py
  6. # 日志路径,加不加引号都行。 注意:等号两边 不能 有空格,否则会提示command找不到
  7. LOG_PATh=log.log
  8. sleep 1
  9. # 如果输入格式不对,给出提示!
  10. tips() {
  11. echo ""
  12. echo "WARNING!!!......Tips, please use command: sh sh_web_app_2006_Svr.sh [start|stop|restart|status]. For example: sh sh_web_app_2006_Svr.sh start "
  13. echo ""
  14. exit 1
  15. }
  16. # 启动方法
  17. start() {
  18. # 重新获取一下pid,因为其它操作如stop会导致pid的状态更新
  19. pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
  20. # -z 表示如果$pid为空时执行
  21. if [ -z $pid ]; then
  22. nohup python3 -u $APP_NAME > log.log 2>&1 &
  23. pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
  24. echo ""
  25. echo "Service ${APP_NAME} is starting! pid=${pid}"
  26. # echo "........................Here is the log.............................."
  27. # echo "....................................................................."
  28. # tail -f $LOG_PATh
  29. echo "........................Start successfully!........................."
  30. else
  31. echo ""
  32. echo "Service ${APP_NAME} is already running,it's pid = ${pid}. If necessary, please use command: sh sh_web_app_2006_Svr.sh restart."
  33. echo ""
  34. fi
  35. }
  36. # 停止方法
  37. stop() {
  38. # 重新获取一下pid,因为其它操作如start会导致pid的状态更新
  39. pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
  40. # -z 表示如果$pid为空时执行。 注意:每个命令和变量之间一定要前后加空格,否则会提示command找不到
  41. if [ -z $pid ]; then
  42. echo ""
  43. echo "Service ${APP_NAME} is not running! It's not necessary to stop it!"
  44. echo ""
  45. else
  46. kill -9 $pid
  47. echo ""
  48. echo "Service stop successfully!pid:${pid} which has been killed forcibly!"
  49. echo ""
  50. fi
  51. }
  52. # 输出运行状态方法
  53. status() {
  54. # 重新获取一下pid,因为其它操作如stop、restart、start等会导致pid的状态更新
  55. pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
  56. # -z 表示如果$pid为空时执行。注意:每个命令和变量之间一定要前后加空格,否则会提示command找不到
  57. if [ -z $pid ];then
  58. echo ""
  59. echo "Service ${APP_NAME} is not running!"
  60. echo ""
  61. else
  62. echo ""
  63. echo "Service ${APP_NAME} is running. It's pid=${pid}"
  64. echo ""
  65. fi
  66. }
  67. # 重启方法
  68. restart() {
  69. echo ""
  70. echo ".............................Restarting.............................."
  71. echo "....................................................................."
  72. # 重新获取一下pid,因为其它操作如start会导致pid的状态更新
  73. pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
  74. # -z 表示如果$pid为空时执行。 注意:每个命令和变量之间一定要前后加空格,否则会提示command找不到
  75. if [ ! -z $pid ]; then
  76. kill -9 $pid
  77. fi
  78. start
  79. echo "....................Restart successfully!..........................."
  80. }
  81. # 根据输入参数执行对应方法,不输入则执行tips提示方法
  82. case "$1" in
  83. "start")
  84. start
  85. ;;
  86. "stop")
  87. stop
  88. ;;
  89. "status")
  90. status
  91. ;;
  92. "restart")
  93. restart
  94. ;;
  95. *)
  96. tips
  97. ;;
  98. esac