From f42bb044443f3257d6d8c06e9639acc53489bfa7 Mon Sep 17 00:00:00 2001 From: Vinna Date: Mon, 20 Jan 2014 15:06:38 +0800 Subject: [PATCH 1/7] Update README.md add the installation of centos --- README.md | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/README.md b/README.md index 3b0845e8..e5d03843 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,132 @@ sudo vim /etc/shadowsocks/config.json sudo /etc/init.d/shadowsocks start ``` +### CentOS + +Install the compile tools +```bash +yum install -y gcc automake autoconf libtool make build-essential autoconf libtool gcc +yum install -y curl curl-devel zlib-devel openssl-devel perl perl-devel cpio expat-devel gettext-devel +``` + +Compile and install +```bash +./configure && make +make install +``` + +Create config.json +```bash +mkdir /etc/shadowsocks +vi /etc/shadowsocks/config.json +``` +Then fill your infomation + +Create the service file +```bash +vi /etc/rc.d/init.d/shadowsocks +``` + +Paste below code in vi +```bash +#!/bin/sh +### BEGIN INIT INFO +# Provides: shadowsocks +# Required-Start: $network $local_fs $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: lightweight secured scoks5 proxy +# Description: Shadowsocks-libev is a lightweight secured +# scoks5 proxy for embedded devices and low end boxes. +# +### END INIT INFO + +# Author: Vinna + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +NAME=shadowsocks +DAEMON=/usr/local/bin/ss-server +prog=$(basename $DAEMON) + +PIDFILE=/var/run/$NAME/$prog.pid +CONFFILE=/etc/$NAME/config.json + +lockfile=/var/lock/subsys/$NAME/$prog + +start() +{ + echo -n $"Starting $prog: " + daemon $DAEMON -c $CONFFILE -f $PIDFILE + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() +{ + echo -n $"Stopping $prog: " + killproc -p $PIDFILE $DAEMON + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f $lockfile + echo + return $retval +} + +restart() { + stop + start +} + +rh_status() { + status $prog +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart) + $1 + ;; + status) + rh_status + ;; + condrestart|try-restart) + rh_status_q || exit 0 + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" + exit 2 +esac +``` +Then save and quit vi + +Ctreate some folder +```bash +mkdir /var/run/shadowsocks +mkdir /var/lock/subsys/shadowsocks +``` +Then start it +```bash +service shadowsocks start +``` + ### Linux For Unix-like systems, especially Debian-based systems, From 7d14bb99b1ccd0333e26bc334e47ff695499d2d3 Mon Sep 17 00:00:00 2001 From: Vinna Date: Mon, 20 Jan 2014 17:34:13 +0800 Subject: [PATCH 2/7] add init script --- rpm/SOURCES/shadowsocks | 85 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 rpm/SOURCES/shadowsocks diff --git a/rpm/SOURCES/shadowsocks b/rpm/SOURCES/shadowsocks new file mode 100644 index 00000000..b62f771b --- /dev/null +++ b/rpm/SOURCES/shadowsocks @@ -0,0 +1,85 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: shadowsocks +# Required-Start: $network $local_fs $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: lightweight secured scoks5 proxy +# Description: Shadowsocks-libev is a lightweight secured +# scoks5 proxy for embedded devices and low end boxes. +# +### END INIT INFO + +# Author: Winny + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +NAME=shadowsocks +DAEMON=/usr/local/bin/ss-server +prog=$(basename $DAEMON) + +PIDFILE=/var/run/$NAME/$prog.pid +CONFFILE=/etc/$NAME/config.json + +lockfile=/var/lock/subsys/$NAME/$prog + +start() +{ + echo -n $"Starting $prog: " + daemon $DAEMON -c $CONFFILE -f $PIDFILE + retval=$? + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() +{ + echo -n $"Stopping $prog: " + killproc -p $PIDFILE $DAEMON + RETVAL=$? + [ $RETVAL -eq 0 ] && rm -f $lockfile + echo + return $retval +} + +restart() { + stop + start +} + +rh_status() { + status $prog +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart) + $1 + ;; + status) + rh_status + ;; + condrestart|try-restart) + rh_status_q || exit 0 + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" + exit 2 +esac From d4dfc6dbf099185050474e51bb79a35904b67b43 Mon Sep 17 00:00:00 2001 From: Vinna Date: Mon, 20 Jan 2014 17:55:52 +0800 Subject: [PATCH 3/7] New one --- rpm/SOURCES/shadowsocks | 176 ++++++++++++++++++++++++---------------- 1 file changed, 107 insertions(+), 69 deletions(-) diff --git a/rpm/SOURCES/shadowsocks b/rpm/SOURCES/shadowsocks index b62f771b..7dd40207 100644 --- a/rpm/SOURCES/shadowsocks +++ b/rpm/SOURCES/shadowsocks @@ -1,85 +1,123 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: shadowsocks -# Required-Start: $network $local_fs $remote_fs -# Required-Stop: $remote_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: lightweight secured scoks5 proxy -# Description: Shadowsocks-libev is a lightweight secured -# scoks5 proxy for embedded devices and low end boxes. -# -### END INIT INFO - -# Author: Winny - -# Source function library. +#!/bin/bash +# +# Script to run Shadowsocks in daemon mode at boot time. +# ScriptAuthor: icyboy +# Revision 1.0 - 14th Sep 2013 +#==================================================================== +# Run level information: +# chkconfig: 2345 99 99 +# Description: lightweight secured scoks5 proxy +# processname: ss-server +# Author: Max Lv ; +# Run "/sbin/chkconfig --add shadowsocks" to add the Run levels. +#==================================================================== + +#==================================================================== +# Paths and variables and system checks. + +# Source function library . /etc/rc.d/init.d/functions -# Source networking configuration. -. /etc/sysconfig/network +# Check that networking is up. +# +[ ${NETWORKING} ="yes" ] || exit 0 -NAME=shadowsocks +# Daemon +NAME=Shadowsocks-Server DAEMON=/usr/local/bin/ss-server -prog=$(basename $DAEMON) -PIDFILE=/var/run/$NAME/$prog.pid -CONFFILE=/etc/$NAME/config.json +# Path to the configuration file. +# +CONF=/usr/local/etc/shadowsocks.json -lockfile=/var/lock/subsys/$NAME/$prog +USER="nobody" +GROUP="nobody" -start() -{ - echo -n $"Starting $prog: " - daemon $DAEMON -c $CONFFILE -f $PIDFILE - retval=$? - echo - [ $retval -eq 0 ] && touch $lockfile - return $retval -} +# Take care of pidfile permissions +mkdir /var/run/$NAME 2>/dev/null || true +chown "$USER:$GROUP" /var/run/$NAME -stop() -{ - echo -n $"Stopping $prog: " - killproc -p $PIDFILE $DAEMON - RETVAL=$? - [ $RETVAL -eq 0 ] && rm -f $lockfile - echo - return $retval -} +# Check the configuration file exists. +# +if [ ! -f $CONF ] ; then +echo "The configuration file cannot be found!" +exit 0 +fi + +# Path to the lock file. +# +LOCK_FILE=/var/lock/subsys/shadowsocks + +# Path to the pid file. +# +PID=/var/run/shadowsocks/shadowsocks.pid -restart() { - stop - start -} -rh_status() { - status $prog +#==================================================================== + +#==================================================================== +# Run controls: + +RETVAL=0 + +# Start shadowsocks as daemon. +# +start() { +if [ -f $LOCK_FILE ]; then +echo "$NAME is already running!" +exit 0 +else +echo -n $"Starting ${NAME}: " +daemon --check $DAEMON --user $USER "$DAEMON -f $PID -c $CONF > /dev/null" +fi + +RETVAL=$? +[ $RETVAL -eq 0 ] && success +echo +[ $RETVAL -eq 0 ] && touch $LOCK_FILE +return $RETVAL } -rh_status_q() { - rh_status >/dev/null 2>&1 + +# Stop shadowsocks. +# +stop() { +echo -n $"Shutting down ${NAME}: " +killproc -p ${PID} +RETVAL=$? +[ $RETVAL -eq 0 ] +rm -f $LOCK_FILE +rm -f ${PID} +echo +return $RETVAL } +# See how we were called. case "$1" in - start) - rh_status_q && exit 0 - $1 - ;; - stop) - rh_status_q || exit 0 - $1 - ;; - restart) - $1 - ;; - status) - rh_status - ;; - condrestart|try-restart) - rh_status_q || exit 0 - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" - exit 2 +start) +start +;; +stop) +stop +;; +restart) +stop +start +;; +condrestart) +if [ -f $LOCK_FILE ]; then +stop +start +RETVAL=$? +fi +;; +status) +status $DAEMON +RETVAL=$? +;; +*) +echo $"Usage: $0 {start|stop|restart|condrestart|status}" +RETVAL=1 esac + +exit $RETVAL \ No newline at end of file From 0557bcd7271dfe106aa84f7861a3ce8a7a20e52e Mon Sep 17 00:00:00 2001 From: Vinna Date: Tue, 21 Jan 2014 17:04:48 +0800 Subject: [PATCH 4/7] fix service failed --- rpm/SOURCES/shadowsocks | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rpm/SOURCES/shadowsocks b/rpm/SOURCES/shadowsocks index 7dd40207..78130c4c 100644 --- a/rpm/SOURCES/shadowsocks +++ b/rpm/SOURCES/shadowsocks @@ -68,7 +68,8 @@ echo "$NAME is already running!" exit 0 else echo -n $"Starting ${NAME}: " -daemon --check $DAEMON --user $USER "$DAEMON -f $PID -c $CONF > /dev/null" +#daemon --check $DAEMON --user $USER "$DAEMON -f $PID -c $CONF > /dev/null" +daemon $DAEMON -c $CONF -f $PID fi RETVAL=$? @@ -120,4 +121,4 @@ echo $"Usage: $0 {start|stop|restart|condrestart|status}" RETVAL=1 esac -exit $RETVAL \ No newline at end of file +exit $RETVAL From c52e30dd202eb476200aadd22550582aa2f907ac Mon Sep 17 00:00:00 2001 From: Vinna Date: Tue, 21 Jan 2014 17:10:35 +0800 Subject: [PATCH 5/7] cancel certain user permisson,because run failed --- rpm/SOURCES/shadowsocks | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpm/SOURCES/shadowsocks b/rpm/SOURCES/shadowsocks index 78130c4c..3f0497b3 100644 --- a/rpm/SOURCES/shadowsocks +++ b/rpm/SOURCES/shadowsocks @@ -30,12 +30,12 @@ DAEMON=/usr/local/bin/ss-server # CONF=/usr/local/etc/shadowsocks.json -USER="nobody" -GROUP="nobody" +#USER="nobody" +#GROUP="nobody" # Take care of pidfile permissions mkdir /var/run/$NAME 2>/dev/null || true -chown "$USER:$GROUP" /var/run/$NAME +#chown "$USER:$GROUP" /var/run/$NAME # Check the configuration file exists. # From bdb597786521dedab9f1423c02459090d8659b1d Mon Sep 17 00:00:00 2001 From: Vinna Date: Tue, 21 Jan 2014 17:12:27 +0800 Subject: [PATCH 6/7] tidy --- rpm/SOURCES/{ => etc/init.d}/shadowsocks | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rpm/SOURCES/{ => etc/init.d}/shadowsocks (100%) diff --git a/rpm/SOURCES/shadowsocks b/rpm/SOURCES/etc/init.d/shadowsocks similarity index 100% rename from rpm/SOURCES/shadowsocks rename to rpm/SOURCES/etc/init.d/shadowsocks From 522eedbf069ecc651685f4b64aec59781cda96a3 Mon Sep 17 00:00:00 2001 From: Vinna Date: Tue, 21 Jan 2014 17:30:18 +0800 Subject: [PATCH 7/7] edit installation of Centos --- README.md | 114 +----------------------------------------------------- 1 file changed, 2 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index e5d03843..cbf406d1 100644 --- a/README.md +++ b/README.md @@ -121,118 +121,8 @@ Compile and install ./configure && make make install ``` - -Create config.json -```bash -mkdir /etc/shadowsocks -vi /etc/shadowsocks/config.json -``` -Then fill your infomation - -Create the service file -```bash -vi /etc/rc.d/init.d/shadowsocks -``` - -Paste below code in vi -```bash -#!/bin/sh -### BEGIN INIT INFO -# Provides: shadowsocks -# Required-Start: $network $local_fs $remote_fs -# Required-Stop: $remote_fs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: lightweight secured scoks5 proxy -# Description: Shadowsocks-libev is a lightweight secured -# scoks5 proxy for embedded devices and low end boxes. -# -### END INIT INFO - -# Author: Vinna - -# Source function library. -. /etc/rc.d/init.d/functions - -# Source networking configuration. -. /etc/sysconfig/network - -NAME=shadowsocks -DAEMON=/usr/local/bin/ss-server -prog=$(basename $DAEMON) - -PIDFILE=/var/run/$NAME/$prog.pid -CONFFILE=/etc/$NAME/config.json - -lockfile=/var/lock/subsys/$NAME/$prog - -start() -{ - echo -n $"Starting $prog: " - daemon $DAEMON -c $CONFFILE -f $PIDFILE - retval=$? - echo - [ $retval -eq 0 ] && touch $lockfile - return $retval -} - -stop() -{ - echo -n $"Stopping $prog: " - killproc -p $PIDFILE $DAEMON - RETVAL=$? - [ $RETVAL -eq 0 ] && rm -f $lockfile - echo - return $retval -} - -restart() { - stop - start -} - -rh_status() { - status $prog -} - -rh_status_q() { - rh_status >/dev/null 2>&1 -} - -case "$1" in - start) - rh_status_q && exit 0 - $1 - ;; - stop) - rh_status_q || exit 0 - $1 - ;; - restart) - $1 - ;; - status) - rh_status - ;; - condrestart|try-restart) - rh_status_q || exit 0 - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" - exit 2 -esac -``` -Then save and quit vi - -Ctreate some folder -```bash -mkdir /var/run/shadowsocks -mkdir /var/lock/subsys/shadowsocks -``` -Then start it -```bash -service shadowsocks start -``` +here is the [init script](rpm/SOURCES/etc/init.d/shadowsocks) . +Notice:default config file is /usr/local/etc/shadowsocks.json ### Linux