1. 创建启动脚本

编辑启动脚本/etc/init.d/sslocal,内容如下。

#!/bin/bash
### BEGIN INIT INFO
# Provides: Shadowsocks-local
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Fast tunnel proxy that helps you bypass firewalls
# Description: A secure socks5 proxy, designed to protect your Internet traffic.
### END INIT INFO

# Author: lynnyq <[email protected]>

name=sslocal
BIN=/usr/bin/sslocal
conf=/etc/shadowsocks/client.json

start(){
nohup $BIN -c $conf >/dev/null 2>&amp;1 &amp;
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name start success"
else
echo "$name start failed"
fi
}

stop(){
pid=`ps -ef | grep -v grep | grep -i "${BIN}" | awk '{print $2}'`
if [[ ! -z $pid ]]; then
kill -9 $pid 
#$BIN -c $conf -d stop
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name stop success"
else
echo "$name stop failed"
fi
else
echo "$name is not running"
RETVAL=1
fi
}

status(){
pid=`ps -ef | grep -v grep | grep -i "${BIN}" | awk '{print $2}'`
if [[ -z $pid ]]; then
echo "$name is not running"
RETVAL=1
else
echo "$name is running with PID $pid"
RETVAL=0
fi
}

case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop
start
RETVAL=$?
;;
*)
echo "Usage: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL

2. 赋予/etc/init.d/sslocal可执行权限

sudo chmod +x /etc/init.d/sslocal

3. 使sslocal开机启动

sudo update-rc.d sslocal defaults

如果想取消开启自动启动,只需要执行

sudo update-rc.d -f sslocal remove
pwrliang Linux ,

Leave a Reply

Your email address will not be published. Required fields are marked *