适用于:shadowsocks-libev-3.0.3

操作系统:CentOS6.8

#!/bin/sh

SHADOWSOCKS_SERVER="/usr/local/shadowsocks-libev/bin/ss-server"
SERVER_CONF="/etc/shadowsocks-libev/config.json"
RET_VAL=

check_running()
{
    ps -ef | grep ss-server | grep -v grep
     ]; then
        return
    else
        return
    fi
}

ss_start()
{
    if check_running; then #shell if判断 返回0 为真
        statusid=`ps -ef | grep ss-server | grep -v grep | awk '{print $2}'`
        echo ${statusid}" is already running..."
        return
    fi
    nohup $SHADOWSOCKS_SERVER -u -c $SERVER_CONF & #至于为什么要加-u参数,是因为要开启udp协议的支持,否则会报 unable to resolve 无法进行DNS查询
    if check_running; then
        echo "Starting shadowsocks success"
    else
        "Starting shadowsocks failed"
        RET_VAL=
    fi
}

ss_stop()
{
    if check_running; then
        ps -ef | grep ss-server | grep -v grep | awk '{print "kill -9 "$2}' | sh
        echo "Stopping shadowsocks success"
    else
        echo "shadowsocks is stopped"
        RET_VAL=
    fi
}

ss_restart()
{
    ss_stop
    ss_start
}

 in
    'start'|'stop'|'restart')
        ss_$
        ;;
    *)
        "Usage: $0 { start | stop | restart }"
        RET_VAL=
        ;;
esac

exit $RET_VAL
05-04 08:39