Created
May 4, 2015 01:50
-
-
Save danisla/6f44fcfc1bbf40c89ff1 to your computer and use it in GitHub Desktop.
Startup script for running daemon java process in docker and tail log file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Script to run a process that runs in the background, | |
# then tail the log file in the forground. | |
# Useful for running apps in Docker container like subsonic, spark or apache. | |
# Author: [email protected] | |
function cleanup { | |
kill `pidof tail` 2>/dev/null | |
kill `pidof java` 2>/dev/null | |
} | |
trap cleanup EXIT | |
trap cleanup INT | |
cleanup | |
# Set file to tail | |
WATCH_FILE="/var/log/messages" | |
### Execute java daemonized program | |
echo "Hello Daemon" | |
RES=$? | |
if [[ ! ${RES} -eq 0 ]]; then | |
echo "ERROR: Exit code was ${RES}" | |
exit 1 | |
fi | |
while ! stat ${WATCH_FILE} >/dev/null 2>&1; do | |
echo "Waiting for ${WATCH_FILE}" | |
sleep 1 | |
done | |
tail -f ${WATCH_FILE} & | |
while kill -0 `pidof java` 2>/dev/null; do | |
sleep 0.5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment