#!/bin/bash
PORT=6800# 這一項可修改爲項目地址
HOME="/var/scrapyd"
BIN="/usr/local/bin/scrapyd"
pid=`netstat -lnopt | grep :$PORT | awk '/python/{gsub(/\/python/,"",$7);print $7;}'`
start(){if[-n "$pid"]; then
echo "server already start,pid:$pid"return0
fi
cd $HOME
nohup $BIN >> $HOME/scrapyd.log 2>&1&
echo "start at port:$PORT"}
stop(){if[-z "$pid"]; then
echo "not find program on port:$PORT"return0
fi
#結束程序,使用訊號2,如果不行可以嘗試訊號9強制結束
kill -9 $pid
echo "kill program use signal 9,pid:$pid"}
status(){if[-z "$pid"]; then
echo "not find program on port:$PORT"else
echo "program is running,pid:$pid"
fi
}
case $1in
start)
start
;;
stop)
stop
;;
status)
status
;;*)
echo "Usage: {start|stop|status}";;
esac
exit 0