From 4d7ae473c3c6cab368e2a925e5ffa1219bb2a319 Mon Sep 17 00:00:00 2001 From: Patrick Li Date: Wed, 11 Sep 2013 11:25:44 +1200 Subject: [PATCH] Ability to change the user and group to run the server as --- debian/shadowsocks.default | 4 ++++ debian/shadowsocks.init | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/debian/shadowsocks.default b/debian/shadowsocks.default index 9c53fdac..e8492e5f 100644 --- a/debian/shadowsocks.default +++ b/debian/shadowsocks.default @@ -11,3 +11,7 @@ START=yes # Configuration file CONFFILE="/etc/shadowsocks/config.json" + +# User and group to run the server as +USER=root +GROUP=root diff --git a/debian/shadowsocks.init b/debian/shadowsocks.init index fef611c3..eceaeecf 100644 --- a/debian/shadowsocks.init +++ b/debian/shadowsocks.init @@ -30,6 +30,9 @@ SCRIPTNAME=/etc/init.d/$NAME [ "$START" = "yes" ] || exit 0 +: ${USER:="root"} +: ${GROUP:="root"} + # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh @@ -43,17 +46,16 @@ SCRIPTNAME=/etc/init.d/$NAME do_start() { # Take care of pidfile permissions - USER=$(egrep '\buser\s*=' $CONFFILE | sed -r 's/.*\buser\s+=\s*(.*);/\1/') mkdir /var/run/$NAME 2>/dev/null || true - chown "$USER" /var/run/$NAME + chown "$USER:$GROUP" /var/run/$NAME # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$GROUP --exec $DAEMON --test > /dev/null \ || return 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ + start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$GROUP --exec $DAEMON -- \ -c "$CONFFILE" -f $PIDFILE \ || return 2 }