A simple chkconfig script to manage starting and stopping the Maven/Jetty server, which supports a SparkJava application
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
#! /bin/bash | |
# | |
# spark-service Start/Stop the Maven Jetty process | |
# | |
# chkconfig: 235 90 60 | |
# description: This will manage the starting and stopping of the Maven/Jetty | |
# server which will render the SparkJava application. It's | |
# rather simple, so don't expect miracles of it. | |
# | |
## --------------------------- | |
## Check for sufficient access | |
## --------------------------- | |
if [ $( whoami ) != "root" ]; then | |
echo "Must be root to run this script"; | |
return 1; | |
fi; | |
# Include the core functions | |
. /etc/init.d/functions | |
## -------------------------- | |
## Variable Declaration | |
## -------------------------- | |
PROJECT_HOME=/var/www/vhosts/phpcloudcasts.com/spark.phpcloudcasts.com/SparkServletExample | |
LOCK_FILE=/var/lock/maven | |
## -------------------------- | |
## Catch abnormal return | |
## -------------------------- | |
trap cleanup 1 2 3 6 | |
cleanup() | |
{ | |
echo "Caught Signal ... cleaning up." | |
rm -rf $LOCK_FILE | |
echo "Done cleanup ... quitting." | |
return 1 | |
} | |
# Simple lock file to record if the script's in progress | |
touch $LOCK_FILE | |
case "$1" in | |
start) | |
echo "Starting maven/jetty" | |
cd $PROJECT_HOME | |
mvn jetty:run & | |
cd - | |
;; | |
stop) | |
echo "Stopping maven/jetty" | |
cd $PROJECT_HOME | |
mvn jetty:stop & | |
cd - | |
;; | |
*) | |
echo "Usage: /etc/init.d/blah {start|stop}" | |
exit 1 | |
;; | |
esac | |
# Remove lock file after use | |
rm $LOCK_FILE | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment