run.sh 1.6 KB
Newer Older
W
init  
wangyunlai.wyl 已提交
1 2
#!/usr/bin/env bash

F
Fankux 已提交
3 4 5
cd $(dirname $0)
DEPLOY_PATH=$(pwd)
echo "DEPLOY_PATH : "${DEPLOY_PATH}
W
init  
wangyunlai.wyl 已提交
6

F
Fankux 已提交
7
BIN='logproxy'
W
init  
wangyunlai.wyl 已提交
8
GPID=0
F
Fankux 已提交
9 10 11 12 13 14 15 16 17 18
function is_running() {
  for pid in $(ps ux | grep ${BIN} | grep -v 'bash ' | grep -v grep | awk '{print $2}'); do
    _path=$(readlink -f /proc/${pid}/cwd)
    if [[ ${?} -eq 0 ]] && [[ ${_path} == ${DEPLOY_PATH} ]]; then
      GPID=${pid}
      echo "is_running : (${GPID})${DEPLOY_PATH} ${BIN} is running!"
      return 1
    fi
  done
  return 0
W
init  
wangyunlai.wyl 已提交
19 20
}

F
Fankux 已提交
21 22
function kill_proc_9() {
  force=$1
W
init  
wangyunlai.wyl 已提交
23

F
Fankux 已提交
24 25 26 27
  if [[ ! -d ${DEPLOY_PATH} ]]; then
    echo "kill_proc : ${DEPLOY_PATH} invalid!"
    return 0
  fi
W
init  
wangyunlai.wyl 已提交
28

F
Fankux 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
  retry=0
  is_running
  status=$?
  while [[ ${status} -eq 1 ]]; do
    if [ ! -z ${force} ]; then
      kill -9 ${GPID}
      echo "kill_proc force : (${GPID})${DEPLOY_PATH} succ!"
    else
      kill ${GPID}
      echo "kill_proc : (${GPID})${DEPLOY_PATH} succ!"
    fi
    sleep 1
    retry=$(expr ${retry} + 1)
    if [ ${retry} -gt 15 ]; then
      force=1
    fi
    is_running
W
init  
wangyunlai.wyl 已提交
46
    status=$?
F
Fankux 已提交
47
  done
W
init  
wangyunlai.wyl 已提交
48

F
Fankux 已提交
49
  return 0
W
init  
wangyunlai.wyl 已提交
50 51
}

F
Fankux 已提交
52 53
start() {
  stop
W
init  
wangyunlai.wyl 已提交
54

F
Fankux 已提交
55 56 57
  if [ ! -d "./run" ]; then
    mkdir ./run
  fi
F
Fankux 已提交
58

F
Fankux 已提交
59 60 61 62 63
  log_path="./log"
  if [ ! -d ${log_path} ]; then
    mkdir ${log_path}
  fi
  log_path=$(readlink -f ${log_path})
W
init  
wangyunlai.wyl 已提交
64

F
Fankux 已提交
65 66 67 68
  chmod u+x ./bin/${BIN} && ./bin/${BIN} -f ./conf/conf.json &>${log_path}/out.log &
  if [ $? -ne 0 ]; then
    exit -1
  fi
W
init  
wangyunlai.wyl 已提交
69

F
Fankux 已提交
70
  is_running
W
init  
wangyunlai.wyl 已提交
71 72
}

F
Fankux 已提交
73 74
stop() {
  kill_proc_9
W
init  
wangyunlai.wyl 已提交
75 76 77 78
}

case C"$1" in
Cstop)
F
Fankux 已提交
79 80 81
  stop
  echo "${BIN} stopped!"
  ;;
W
init  
wangyunlai.wyl 已提交
82
Cstart)
F
Fankux 已提交
83 84 85
  start
  echo "${BIN} started!"
  ;;
W
init  
wangyunlai.wyl 已提交
86
Cdebug)
F
Fankux 已提交
87 88 89
  debug
  echo "${BIN} started!"
  ;;
W
init  
wangyunlai.wyl 已提交
90
Cstatus)
F
Fankux 已提交
91 92 93 94 95
  is_running
  status=$?
  echo "status : ${status}"
  exit ${status}
  ;;
W
init  
wangyunlai.wyl 已提交
96
C*)
F
Fankux 已提交
97 98
  echo "Usage: $0 {start|stop|status}"
  ;;
W
init  
wangyunlai.wyl 已提交
99
esac