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

Merge pull request #15 from fankux/master

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