一、cow安装
请参考链接1
二、监控启动
监控工具:supervisor
[program:cow] command=/home/pi/tools/cow/cow-linux-armv7l-0.9.8 directory=/home/pi/tools/cow user=pi autostart=true autorestart=true stopsignal=KILL killasgroup=true stopasgroup=true redirect_stderr=true stdout_logfile=/home/pi/tools/cow/cow.log environment=HOME=/home/pi
如上所示。以前不能引导是因为少了HOME变量
以下全部作废:
配置:
[program:cow] command=sudo -u root -H -- /usr/local/bin/cow >/var/log/cow 2>&1 & directory=/etc/cow user=root autostart=true autorestart=true
启动配置:
来源:https://github.com/cyfdecyf/cow/blob/master/doc/init.d/cow
#!/bin/bash ### BEGIN INIT INFO # Provides: cow # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: COW: Climb Over the Wall http proxy # Description: Automatically detect blocked site and use parent proxy. ### END INIT INFO # Put this script under /etc/init.d/, then run "update-rc.d cow defaults". # Note: this script requires sudo in order to run COW as the specified # user. Please change the following variables in order to use this script. # COW will search for rc/direct/block/stat file under user's $HOME/.cow/ directory. BIN=/usr/local/bin/cow USER=root GROUP=grp PID_DIR=/var/run PID_FILE=$PID_DIR/cow.pid LOG_FILE=/var/log/cow RET_VAL=0 check_running() { if [[ -r $PID_FILE ]]; then read PID <$PID_FILE if [[ -d "/proc/$PID" ]]; then return 0 else rm -f $PID_FILE return 1 fi else return 2 fi } do_status() { check_running case $? in 0) echo "cow running with PID $PID" ;; 1) echo "cow not running, remove PID file $PID_FILE" ;; 2) echo "Could not find PID file $PID_FILE, cow does not appear to be running" ;; esac return 0 } do_start() { if [[ ! -d $PID_DIR ]]; then echo "creating PID dir" mkdir $PID_DIR || echo "failed creating PID directory $PID_DIR"; exit 1 chown $USER:$GROUP $PID_DIR || echo "failed creating PID directory $PID_DIR"; exit 1 chmod 0770 $PID_DIR fi if check_running; then echo "cow already running with PID $PID" return 0 fi echo "starting cow" # sudo will set the group to the primary group of $USER sudo -u $USER -H -- $BIN >$LOG_FILE 2>&1 & PID=$! echo $PID > $PID_FILE sleep 0.3 if ! check_running; then echo "start failed" return 1 fi echo "cow running with PID $PID" return 0 } do_stop() { if check_running; then echo "stopping cow with PID $PID" kill $PID rm -f $PID_FILE else echo "Could not find PID file $PID_FILE" fi } do_restart() { do_stop do_start } case "$1" in start|stop|restart|status) do_$1 ;; *) echo "Usage: cow {start|stop|restart|status}" RET_VAL=1 ;; esac exit $RET_VAL
三、问题
1、sudo: sorry, you must have a tty to run sudo错误。
表述:无法通过supervisor移动
来源:/var/log/cow日志文件
解决方法:
使用不同账户,执行执行脚本时候sudo经常会碰到 sudo: sorry, you must have a tty to run sudo这个情况,其实修改一下sudo的配置就好了
vi /etc/sudoers (最好用visudo命令)
注释掉 Default requiretty 一行
#Default requiretty
意思就是sudo默认需要tty终端。注释掉就可以在后台执行了。-
参考链接
https://github.com/cyfdecyf/cow
http://www.linuxidc.com/Linux/2012-11/75153.htm
https://my.oschina.net/crooner/blog/395069