edge-actuator.sh 1.2 KB

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