Skip to content

Commit

Permalink
Init script to read config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpartel committed Sep 23, 2012
1 parent 0aaae7b commit 4506d2d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/daemon.log
/config.properties
10 changes: 9 additions & 1 deletion initscripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#!/bin/bash -e
THISDIR=`dirname "$0"`
BASEDIR=`dirname "$THISDIR"`
THISDIR=`realpath "$THISDIR"`
BASEDIR=`realpath "$BASEDIR"`

TEMPLATE="$THISDIR/template.txt"
SCRIPT_NAME=tmc-comet
TARGET="/etc/init.d/$SCRIPT_NAME"
RUN_AS=`stat -c '%U' "$BASEDIR"`
PORT=${1:-8080}
CONFIG_FILE=$BASEDIR/config.properties

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

echo "Installing into $TARGET with port $PORT."
echo "Configuring it to run as $RUN_AS (the current owner of the directory)."
echo "The config file will be read from $CONFIG_FILE."
echo

cat "$TEMPLATE" |
sed "s@__BASEDIR__@$BASEDIR@" |
sed "s@__NAME__@$SCRIPT_NAME@" |
sed "s@__USER__@$RUN_AS@" |
sed "s@__PORT__@$PORT@" > $TARGET
sed "s@__PORT__@$PORT@" |
sed "s@__CONFIG_FILE__@$CONFIG_FILE@" > $TARGET
chmod a+x "$TARGET"

echo "Setting to start/stop by default"
Expand Down
9 changes: 5 additions & 4 deletions initscripts/template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
# Short-Description: Starts TMC's comet server.
### END INIT INFO

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

cd "$BASEDIR"

Expand All @@ -31,7 +32,7 @@ start() {
fi

echo -n "Starting jetty"
su -c 'mvn -Djetty.port='"$HTTP_PORT"' jetty:start >> '"$LOG_FILE"' 2>&1 &' "$RUN_AS"
su -c 'mvn -Dfi.helsinki.cs.tmc.comet.configFile='"$CONFIG_FILE"' -Djetty.port='"$HTTP_PORT"' jetty:start >> '"$LOG_FILE"' 2>&1 &' "$RUN_AS"

# Wait until started
for i in `seq 1 15`; do
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/fi/helsinki/cs/tmc/comet/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ private static void loadProperties(Properties props, File file) throws IOExcepti
props.load(reader);
} finally {
try {
reader.close();
if (reader != null) {
reader.close();
}
} catch (IOException e) {
// Ignore
}
Expand Down

0 comments on commit 4506d2d

Please sign in to comment.