1 Star 0 Fork 0

蒋汶真/quitter-daemon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
daemonManage.sh 2.98 KB
一键复制 编辑 原始数据 按行查看 历史
shoukaiseki 提交于 2019-05-09 11:34 . ch
#!/bin/bash
#启用虚拟环境
_SERVER_NAME="manage_daemon"
PID_NAME=$_SERVER_NAME".pid"
#PID存放
_RUNPID=/tmp/$PID_NAME
start()
{
if [ ! -z "$_RUNPID" ]; then
if [ -f "$_RUNPID" ]; then
if [ -s "$_RUNPID" ]; then
echo "Existing PID file found during start."
if [ -r "$_RUNPID" ]; then
PID=`cat "$_RUNPID"`
ps -p $PID >/dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "$_SERVER_NAME appears to still be running with PID $PID. Start aborted."
echo "If the following process is not a Tomcat process, remove the PID file[$_RUNPID] and try again:"
ps -f -p $PID
exit 1
else
echo "Removing/clearing stale PID file."
rm -f "$_RUNPID" >/dev/null 2>&1
if [ $? != 0 ]; then
if [ -w "$_RUNPID" ]; then
cat /dev/null > "$_RUNPID"
else
echo "Unable to remove or clear stale PID file. Start aborted."
exit 1
fi
fi
fi
else
echo "Unable to read PID file. Start aborted."
exit 1
fi
else
rm -f "$_RUNPID" >/dev/null 2>&1
if [ $? != 0 ]; then
if [ ! -w "$_RUNPID" ]; then
echo "Unable to remove or write to empty PID file. Start aborted."
exit 1
fi
fi
fi
fi
fi
_CONSOLE_LOG=/tmp/manage_daemon_`date +%Y-%m-%d`.log
nohup pipenv run python3 manage.py runserver 0.0.0.0:28555 >> $_CONSOLE_LOG 2>&1 & echo $! > $_RUNPID
echo "start end,you can command..."
echo " tail -f $_CONSOLE_LOG"
tail -f $_CONSOLE_LOG
}
stop()
{
shift
SLEEP=5
if [ ! -z "$_RUNPID" ]; then
if [ -f "$_RUNPID" ]; then
if [ -s "$_RUNPID" ]; then
kill -0 `cat "$_RUNPID"` >/dev/null 2>&1
if [ $? -gt 0 ]; then
echo "PID file found but either no matching process was found or the current user does not have permission to stop the process. Stop aborted."
exit 1
fi
else
echo "PID file is empty and has been ignored."
fi
else
echo "$_RUNPID was set but the specified file does not exist. Is $_SERVER_NAME running? Stop aborted."
exit 1
fi
fi
echo "asus....."
# stop failed. Shutdown port disabled? Try a normal kill.
if [ ! -z "$_RUNPID" ]; then
echo "The stop command failed. Attempting to signal the process to stop through OS signal."
kill -15 `cat "$_RUNPID"` >/dev/null 2>&1
rm -f "$_RUNPID" >/dev/null 2>&1
fi
echo "stop end"
}
debug()
{
pipenv run python3 manage.py runserver 0.0.0.0:28555
}
if [ "$1" = "start" ] ; then
start
elif [ "$1" = "debug" ] ; then
debug
elif [ "$1" = "stop" ]; then
stop
elif [ "$1" = "restart" ]; then
stop
start
elif [ "$1" = "-h" ]; then
# $0 是脚本名称
echo "Usage: $0 ( commands ... )"
echo "commands:"
echo " start 启动服务"
echo " stop 停止服务"
exit 1
else
debug
fi
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/shoukaiseki/quitter-daemon.git
git@gitee.com:shoukaiseki/quitter-daemon.git
shoukaiseki
quitter-daemon
quitter-daemon
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385