Created
November 2, 2015 01:00
-
-
Save claytantor/3eeade1cddfe3d1907e1 to your computer and use it in GitHub Desktop.
A shade/shadow jar that has jetty runnable init.d service.
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 | |
# | |
# Startup script for a spring boot project | |
# | |
# chkconfig: - 84 16 | |
# description: project | |
# Source function library. | |
[ -f "/etc/rc.d/init.d/functions" ] && . /etc/rc.d/init.d/functions | |
[ -z "$JAVA_HOME" -a -x /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh | |
# the name of the project, will also be used for the war file, log file, ... | |
PROJECT_NAME=dronze | |
# the user which should run the service | |
SERVICE_USER=root | |
# base directory for the spring boot jar | |
DRONEZEAPP_HOME=/usr/local/$PROJECT_NAME | |
export DRONEZEAPP_HOME | |
# the spring boot war-file | |
DRONZEAPP_JAR="$DRONEZEAPP_HOME/$PROJECT_NAME-app.jar" | |
# java executable for spring boot app, change if you have multiple jdks installed | |
DRONZEAPP_JAVA=/usr/bin/java | |
# spring boot log-file | |
LOG="/var/log/$PROJECT_NAME/$PROJECT_NAME.log" | |
LOCK="/var/lock/subsys/$PROJECT_NAME" | |
RETVAL=0 | |
pid_of_dronze_app() { | |
pgrep -f "java.*$PROJECT_NAME" | |
} | |
start() { | |
[ -e "$LOG" ] && cnt=`wc -l "$LOG" | awk '{ print $1 }'` || cnt=1 | |
echo -n $"Starting $PROJECT_NAME: " | |
cd "$DRONEZEAPP_HOME" | |
su $SERVICE_USER -c "nohup $DRONZEAPP_JAVA -jar \"$DRONZEAPP_JAR\" >> \"$LOG\" 2>&1 &" | |
pid_of_dronze_app > /dev/null | |
RETVAL=$? | |
[ $RETVAL = 0 ] && success $"$STRING" || failure $"$STRING" | |
echo | |
[ $RETVAL = 0 ] && touch "$LOCK" | |
} | |
stop() { | |
echo -n "Stopping $PROJECT_NAME: " | |
pid=`pid_of_dronze_app` | |
[ -n "$pid" ] && kill $pid | |
RETVAL=$? | |
cnt=10 | |
while [ $RETVAL = 0 -a $cnt -gt 0 ] && | |
{ pid_of_dronze_app > /dev/null ; } ; do | |
sleep 1 | |
((cnt--)) | |
done | |
[ $RETVAL = 0 ] && rm -f "$LOCK" | |
[ $RETVAL = 0 ] && success $"$STRING" || failure $"$STRING" | |
echo | |
} | |
status() { | |
pid=`pid_of_dronze_app` | |
if [ -n "$pid" ]; then | |
echo "$PROJECT_NAME (pid $pid) is running..." | |
return 0 | |
fi | |
if [ -f "$LOCK" ]; then | |
echo $"${base} dead but subsys locked" | |
return 2 | |
fi | |
echo "$PROJECT_NAME is stopped" | |
return 3 | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status | |
;; | |
restart) | |
stop | |
start | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|status}" | |
exit 1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment