Skip to content

Commit

Permalink
Init script: run jetty as the user owning the tmc-comet directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpartel committed Sep 23, 2012
1 parent 121db16 commit f48467b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 7 additions & 2 deletions initscripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions initscripts/template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
BASEDIR=__BASEDIR__
LOG_FILE="$BASEDIR/daemon.log"
HTTP_PORT=8080
RUN_AS=__USER__

cd "$BASEDIR"

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f48467b

Please sign in to comment.