centralbase.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. APP_NAME=/home/geo/geo-test/microarch_bg/microarch_bg_centralbase-0.0.1-SNAPSHOT.jar
  2. #使用说明,用来提示输入参数
  3. usage() {
  4. echo "Usage: sh gateway.sh [start|stop|restart|status]"
  5. exit 1
  6. }
  7. #检查程序是否在运行
  8. is_exist(){
  9. pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`
  10. #如果不存在返回1,存在返回0
  11. if [ -z "${pid}" ]; then
  12. return 1
  13. else
  14. return 0
  15. fi
  16. }
  17. #启动方法
  18. start(){
  19. is_exist
  20. if [ $? -eq 0 ]; then
  21. echo "${APP_NAME} is already running. pid=${pid}"
  22. else
  23. nohup java -jar -Xmx128m ${APP_NAME} >/home/geo/geo-test/microarch_bg/centralbase.out 2>&1 &
  24. fi
  25. }
  26. #停止方法
  27. stop(){
  28. is_exist
  29. if [ $? -eq "0" ]; then
  30. kill -9 $pid
  31. else
  32. echo "${APP_NAME} is not running"
  33. fi
  34. }
  35. #输出运行状态
  36. status(){
  37. is_exist
  38. if [ $? -eq "0" ]; then
  39. echo "${APP_NAME} is running. Pid is ${pid}"
  40. else
  41. echo "${APP_NAME} is NOT running."
  42. fi
  43. }
  44. #重启
  45. restart(){
  46. stop
  47. sleep 5
  48. start
  49. }
  50. #根据输入参数,选择执行对应方法,不输入则执行使用说明
  51. case "$1" in
  52. "start")
  53. start
  54. ;;
  55. "stop")
  56. stop
  57. ;;
  58. "status")
  59. status
  60. ;;
  61. "restart")
  62. restart
  63. ;;
  64. *)
  65. usage
  66. ;;
  67. esac