I created a (Debian) init Script for an executable Jar file:
[...]
NAME=NameOfMyShellScript
DAEMON="/usr/share/myApp/bin/$NAME"
USER="myUser"
PIDFILE="/usr/share/myApp/run/$NAME.pid"
EXTRA_ARGS=" -c $USER --background --make-pidfile"
[...]
start-stop-daemon --start --quiet $EXTRA_ARGS --pidfile $PIDFILE --startas $DAEMON --
[...]
My init script basically just invokes start-stop-daemon which executes a shell script:
#!/bin/sh
XNAME="hellofellow_1"
SCALATRA_ENV="development"
TMP_DIR="tmp/$XNAME/"
JAVA_OPTIONS="-Xmx2024M -XX:MaxPermSize=512M"
LOGFILE="logs/$XNAME.log"
PORT="8080"
JAVA_OPTIONS="$JAVA_OPTIONS -Djava.io.tmpdir=$TMP_DIR \
-Dorg.scalatra.environment=$SCALATRA_ENV"
cd $(dirname $0)/../
rm -Rf $TMP_DIR*
exec java $JAVA_OPTIONS -jar current/myJarFile.jar $PORT > $LOGFILE
This works so far, my applications runs and any output is written to $LOGFILE.
To enhance logging with rotation I then tried to to something like:
exec java $JAVA_OPTIONS -jar current/myJarFile.jar $PORT | multilog t s131072 n100 '!/bin/gzip' /my/log/dir
Logging works perfect, but now start-stop-daemon writes the PID of multilog to $PIDFILE and not the PID of my java process (so stopping does not work anymore).
Is there any "pipeline magic" that can be used to prevent that from happening? :)