scrapyd默认不会以daemon守护方式运行,想要转入后台守护运行的话,其实使用nohup就可以了:
nohup scrapyd >> /var/log/scrapyd.log 2>&1 &
以下是 scrapyd 注册成系统后台服务和启动项的步骤:
一、设置为系统后台服务
1、新建文件/etc/init.d/scrapyd,名称为scrapyd
#!/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"
return 0
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"
return 0
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 $1 in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo "Usage: {start|stop|status}"
;;
esac
exit 0
2、新建目录/var/scrapyd
3、大功告成:
可使用命令进行操作了(启动停止状态)
service scrapyd {start|stop|status}
二、设置为系统启动项
1、启用禁用命令:
sysv-rc-conf scrapyd on/off