From f48467b2088ded95e42faab9c405b738b24ca7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A4rtel?= Date: Sun, 23 Sep 2012 16:22:03 +0300 Subject: [PATCH] Init script: run jetty as the user owning the tmc-comet directory. --- initscripts/install.sh | 9 +++++++-- initscripts/template.txt | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/initscripts/install.sh b/initscripts/install.sh index 677732b..633e604 100755 --- a/initscripts/install.sh +++ b/initscripts/install.sh @@ -4,11 +4,16 @@ BASEDIR=`dirname "$THISDIR"` TEMPLATE="$THISDIR/template.txt" SCRIPT_NAME=tmc-comet TARGET="/etc/init.d/$SCRIPT_NAME" +RUN_AS=`stat -c '%U' "$BASEDIR"` which nc > /dev/null || (echo "Error: 'nc' command missing! Please install netcat."; exit 1) -echo "Installing into $TARGET" -cat "$TEMPLATE" | sed "s@__BASEDIR__@$BASEDIR@" | sed "s@__NAME__@$SCRIPT_NAME@" > $TARGET +echo "Installing into $TARGET." +echo "Configuring it to run as $RUN_AS (the current owner of the directory)." +cat "$TEMPLATE" | + sed "s@__BASEDIR__@$BASEDIR@" | + sed "s@__NAME__@$SCRIPT_NAME@" | + sed "s@__USER__@$RUN_AS@" > $TARGET chmod a+x "$TARGET" echo "Setting to start/stop by default" diff --git a/initscripts/template.txt b/initscripts/template.txt index db63b5a..79f6e87 100644 --- a/initscripts/template.txt +++ b/initscripts/template.txt @@ -12,6 +12,7 @@ BASEDIR=__BASEDIR__ LOG_FILE="$BASEDIR/daemon.log" HTTP_PORT=8080 +RUN_AS=__USER__ cd "$BASEDIR" @@ -30,7 +31,7 @@ start() { fi echo -n "Starting jetty" - mvn jetty:start >> "$LOG_FILE" 2>&1 & + su -c 'mvn jetty:start >> '"$LOG_FILE"' 2>&1 &' "$RUN_AS" # Wait until started for i in `seq 1 15`; do @@ -47,7 +48,7 @@ start() { stop() { echo "Stopping jetty" - mvn jetty:stop >> "$LOG_FILE" 2>&1 + su -c 'mvn jetty:stop >> '"$LOG_FILE"' 2>&1' "$RUN_AS" } case "$1" in