sh boot status

    1. #!/bin/bash
    2. APP_NAME=elastic
    3. cd `dirname $0`
    4. # 使用说明,用来提示输入参数
    5. usage() {
    6. echo "Usage: sh boot [APP_NAME] [start|stop|restart|status]"
    7. exit 1
    8. }
    9. # 检查程序是否在运行
    10. is_exist(){
    11. # 获取PID
    12. PID=$(ps -ef |grep ${APP_NAME} |grep -v grep |awk '{print $2}')
    13. # -z "${pid}"判断pid是否存在,如果不存在返回1,存在返回0
    14. if [ -z "${PID}" ]; then
    15. # 如果进程不存在返回1
    16. return 1
    17. els
    18. # 进程存在返回0
    19. return 0
    20. fi
    21. }
    22. # 定义启动程序函数
    23. start(){
    24. is_exist
    25. if [ $? -eq "0" ]; then
    26. echo "${APP_NAME} is already running, PID=${PID}"
    27. else
    28. sh bin/elasticsearch -d
    29. is_exist
    30. echo "${APP_NAME} start success, PID=${PID}"
    31. fi
    32. }
    33. # 停止进程函数
    34. stop(){
    35. is_exist
    36. if [ $? -eq "0" ]; then
    37. kill -9 ${PID}
    38. # 检测是否停止
    39. COUNT=1
    40. while [ $COUNT -eq 1 ]
    41. do
    42. echo -e ".\c"
    43. sleep 1
    44. is_exist
    45. if [ -z "${PID}" ]; then
    46. COUNT=0
    47. echo "${APP_NAME} process stop"
    48. fi
    49. done
    50. else
    51. echo "There is not the process of ${APP_NAME}"
    52. fi
    53. }
    54. # 重启进程函数
    55. restart(){
    56. stop
    57. start
    58. }
    59. # 查看进程状态
    60. status(){
    61. is_exist
    62. if [ $? -eq "0" ]; then
    63. echo "${APP_NAME} is running, PID=${PID}"
    64. else
    65. echo "There is not the process of ${APP_NAME}"
    66. fi
    67. }
    68. case $1 in
    69. "start")
    70. start
    71. ;;
    72. "stop")
    73. stop
    74. ;;
    75. "restart")
    76. restart
    77. ;;
    78. "status")
    79. status
    80. ;;
    81. *)
    82. usage
    83. ;;
    84. esac
    85. exit 0