dlview.sh 1.2 KB

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