設定scrapyd為系統後臺服務及系統啟動項
阿新 • • 發佈:2019-02-09
whereis scrapyd
一、設定為系統後臺服務
1、新建檔案/etc/init.d/scrapyd
vi /etc/init.d/scrapyd
sudo chmod 755 /etc/init.d/scrapyd
#!/bin/bash # chkconfig: 2345 20 80 # description: Srapyd PORT=6800 HOME="/var/scrapyd" BIN="/usr/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
mkdir /var/scrapyd
3、命令操作(啟動停止狀態)
service scrapyd {start|stop|status}
二、設定為系統啟動項
啟用禁用命令:sysv-rc-conf scrapyd on/off
sysv-rc-conf scrapyd on
或者chkconfig --add/del scrapydchkconfig --add scrapyd
chkconfig --del scrapyd
chkconfig --list
三、遠端訪問
預設scrapyd啟動bind繫結的ip地址是127.0.0.1埠是:6800,這裡為了其他主機可以訪問,需將ip地址設定為0.0.0.0
vi /usr/lib/python2.7/site-packages/scrapyd/default_scrapyd.conf
bind_address = 0.0.0.0