1 Star 0 Fork 39

一只熊猫 / novel-spider

forked from cnjack / novel-spider
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
control 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
admin_f936 提交于 2016-11-20 01:08 . add control script
#!/bin/bash
WORKSPACE=$(cd $(dirname $0)/; pwd)
cd $WORKSPACE
app=novel-spider
pidfile=var/app.pid
logfile=var/app.log
function check_pid() {
if [ -f $pidfile ];then
pid=`cat $pidfile`
if [ -n $pid ]; then
running=`ps -p $pid|grep -v "PID TTY" |wc -l`
return $running
fi
fi
return 0
}
function start() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo -n "$app now is running already, pid="
cat $pidfile
return 1
fi
nohup ./$app &> $logfile &
sleep 1
running=`ps -p $! | grep -v "PID TTY" | wc -l`
if [ $running -gt 0 ];then
echo $! > $pidfile
echo "$app started..., pid=$!"
else
echo "$app failed to start"
return 1
fi
}
function stop() {
check_pid
running=$?
if [ $running -gt 0 ];then
pid=`cat $pidfile`
kill $pid
rm -f $pidfile
echo "$app stoped"
else
echo "$app already stoped"
fi
}
function restart() {
stop
sleep 1
start
}
function status() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo "started"
else
echo "stoped"
fi
}
function tailf() {
tail -f $logfile
}
function build() {
go build -o $app
if [ $? -ne 0 ]; then
exit $?
fi
}
function pack() {
build
version=`./$app -v`
tar zcvf $app-$version.tar.gz control cfg.json $app
}
function packbin() {
build
version=`./$app -v`
tar zcvf $app-bin-$version.tar.gz $app
}
function help() {
echo "$0 pid|reload|build|pack|packbin|start|stop|restart|status|tail"
}
function pid() {
cat $pidfile
}
function reload() {
build
restart
tailf
}
if [ "$1" == "" ]; then
help
elif [ "$1" == "stop" ];then
stop
elif [ "$1" == "start" ];then
start
elif [ "$1" == "restart" ];then
restart
elif [ "$1" == "status" ];then
status
elif [ "$1" == "tail" ];then
tailf
elif [ "$1" == "build" ];then
build
elif [ "$1" == "pack" ];then
pack
elif [ "$1" == "packbin" ];then
packbin
elif [ "$1" == "pid" ];then
pid
elif [ "$1" == "reload" ];then
reload
else
help
fi
Go
1
https://gitee.com/apandas/novel-spider.git
git@gitee.com:apandas/novel-spider.git
apandas
novel-spider
novel-spider
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891