Skip to content

Instantly share code, notes, and snippets.

@settermjd
Created March 2, 2015 10:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save settermjd/c0157202fd803d944993 to your computer and use it in GitHub Desktop.
A simple chkconfig script to manage starting and stopping the Maven/Jetty server, which supports a SparkJava application
#! /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