Skip to content

Commit

Permalink
Init scripts: allow specifying port number.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpartel committed Sep 23, 2012
1 parent f48467b commit ccf52e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Clients authenticate by sending an ext parameter `authentication` containing the

## Configuration and running ##

Install an init script (for debian-based systems) using `initscripts/install.sh`.
Install an init script (for debian-based systems) using `initscripts/install.sh [port]`. The port defaults to 8080.

To run the server manually, do `mvn -Dfi.helsinki.cs.tmc.comet.configFile=/path/to/file.properties jetty:start`. The configuration file should not be world-readable and must have the following definitions.

Expand Down
6 changes: 4 additions & 2 deletions initscripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ TEMPLATE="$THISDIR/template.txt"
SCRIPT_NAME=tmc-comet
TARGET="/etc/init.d/$SCRIPT_NAME"
RUN_AS=`stat -c '%U' "$BASEDIR"`
PORT=${1:-8080}

which nc > /dev/null || (echo "Error: 'nc' command missing! Please install netcat."; exit 1)

echo "Installing into $TARGET."
echo "Installing into $TARGET with port $PORT."
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
sed "s@__USER__@$RUN_AS@" |
sed "s@__PORT__@$PORT@" > $TARGET
chmod a+x "$TARGET"

echo "Setting to start/stop by default"
Expand Down
8 changes: 4 additions & 4 deletions initscripts/template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

BASEDIR=__BASEDIR__
LOG_FILE="$BASEDIR/daemon.log"
HTTP_PORT=8080
HTTP_PORT=__PORT__
RUN_AS=__USER__

cd "$BASEDIR"
Expand All @@ -31,7 +31,7 @@ start() {
fi

echo -n "Starting jetty"
su -c 'mvn jetty:start >> '"$LOG_FILE"' 2>&1 &' "$RUN_AS"
su -c 'mvn -Djetty.port='"$HTTP_PORT"' jetty:start >> '"$LOG_FILE"' 2>&1 &' "$RUN_AS"

# Wait until started
for i in `seq 1 15`; do
Expand All @@ -42,13 +42,13 @@ start() {

echo
echo "Failed to start in 15 seconds. Check $LOG_FILE"
echo "If this is the first startup, it might take a while to download dependencies."
echo "If this is the first startup, the server may start after dependencies have been downloaded."
exit 1
}

stop() {
echo "Stopping jetty"
su -c 'mvn jetty:stop >> '"$LOG_FILE"' 2>&1' "$RUN_AS"
su -c 'mvn -Djetty.port='"$HTTP_PORT"' jetty:stop >> '"$LOG_FILE"' 2>&1' "$RUN_AS"
}

case "$1" in
Expand Down

0 comments on commit ccf52e0

Please sign in to comment.