未验证 提交 2da1935f 编写于 作者: F Fankux 提交者: GitHub

Merge pull request #15 from fankux/master

remaster run script
#!/usr/bin/env bash #!/usr/bin/env bash
BIN='logproxy' cd $(dirname $0)
DEPLOY_PATH=$(pwd)
echo "DEPLOY_PATH : "${DEPLOY_PATH}
BIN='logproxy'
GPID=0 GPID=0
function is_running() function is_running() {
{ for pid in $(ps ux | grep ${BIN} | grep -v 'bash ' | grep -v grep | awk '{print $2}'); do
DEPLOY_PATH=$1 _path=$(readlink -f /proc/${pid}/cwd)
PROC_BIN_NAME=$2 if [[ ${?} -eq 0 ]] && [[ ${_path} == ${DEPLOY_PATH} ]]; then
for pid in `ps ux | grep ${PROC_BIN_NAME} | awk '{print $2}'`; do GPID=${pid}
_path=$(readlink -f /proc/${pid}/cwd) echo "is_running : (${GPID})${DEPLOY_PATH} ${BIN} is running!"
if [[ ${?} -eq 0 ]] && [[ ${_path} = ${DEPLOY_PATH} ]]; then return 1
GPID=${pid} fi
echo "is_running : (${GPID})${DEPLOY_PATH} ${PROC_BIN_NAME} is running!" done
return 1 return 0
fi
done
return 0
} }
function kill_proc_9() function kill_proc_9() {
{ force=$1
DEPLOY_PATH=$1
PROC_BIN_NAME=$2
force=$3
[[ ! -d ${DEPLOY_PATH} ]] && { if [[ ! -d ${DEPLOY_PATH} ]]; then
echo "@@@@@@@@@@@@@@@ kill_proc : ${DEPLOY_PATH} invalid!" echo "kill_proc : ${DEPLOY_PATH} invalid!"
return 0 return 0
} fi
retry=0 retry=0
is_running ${DEPLOY_PATH} ${PROC_BIN_NAME} 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
status=$? status=$?
while [[ ${status} -eq 1 ]]; do done
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 ${DEPLOY_PATH} ${PROC_BIN_NAME}
status=$?
done
return 0 return 0
} }
start() start() {
{ stop
stop
if [ ! -d "./run" ]; then if [ ! -d "./run" ]; then
mkdir ./run mkdir ./run
fi fi
log_path="./log" log_path="./log"
if [ ! -d ${log_path} ]; then if [ ! -d ${log_path} ]; then
mkdir ${log_path} mkdir ${log_path}
fi fi
log_path=`readlink -f ${log_path}` log_path=$(readlink -f ${log_path})
chmod u+x ./bin/${BIN} && ./bin/${BIN} -f ./conf/conf.json &> ${log_path}/out.log& chmod u+x ./bin/${BIN} && ./bin/${BIN} -f ./conf/conf.json &>${log_path}/out.log &
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
exit -1 exit -1
fi fi
is_running ${deploy_path} ${BIN} is_running
} }
stop() stop() {
{ kill_proc_9
cd `dirname $0`
echo "work path : "`pwd`
deploy_path=`pwd`
kill_proc_9 ${deploy_path} ${BIN}
} }
case C"$1" in case C"$1" in
Cstop) Cstop)
stop stop
echo "${BIN} stopped!" echo "${BIN} stopped!"
;; ;;
Cstart) Cstart)
start start
echo "${BIN} started!" echo "${BIN} started!"
;; ;;
Cdebug) Cdebug)
debug debug
echo "${BIN} started!" echo "${BIN} started!"
;; ;;
Cstatus) Cstatus)
cd `dirname $0` is_running
echo "work path : "`pwd` status=$?
deploy_path=`pwd` echo "status : ${status}"
exit ${status}
is_running ${deploy_path} ${BIN} ;;
status=$?
echo "status : ${status}"
exit ${status}
;;
C*) C*)
echo "Usage: $0 {start|stop|status}" echo "Usage: $0 {start|stop|status}"
;; ;;
esac esac
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册