if [ "$1" = "start" ] ; then
echo "start..."

elif [ "$1" = "stop" ] ; then
echo "solr stopp..."

elif [ "$1" = "restart" ] ; then
echo "solr restarting..."

elif [ "$1" = "status" ] ; then
echo "solr status: "

else
echo "Usage: solr.sh start|stop|restart|status"
fi

start() {
pid=`ps aux|grep /usr/local/apache-solr-3.6.0/example/start.jar|grep solr.solr.home| awk '{print $2}'`

if [ $pid ]; then
echo "solr is already running..."

else
echo "solr starting..."
setsid java -Dsolr.solr.home=/usr/local/apache-solr-3.6.0/example/solr-syk -jar /usr/local/apache-solr-3.6.0/example/start.jar >> /usr/local/apache-solr-3.6.0/example/logs/solr.log 2>&1 &
fi
}

stop() {
echo "do stopping..."
pid=`ps aux|grep /usr/local/apache-solr-3.6.0/example/start.jar|grep solr.solr.home| awk '{print $2}'`

if [ $pid ]; then
echo $pid " solr killing..."
kill $pid

sleep 1
else
echo "solr not running."
fi
}

status() {
pid=`ps aux|grep /usr/local/apache-solr-3.6.0/example/start.jar|grep solr.solr.home| awk '{print $2}'`

if [ $pid ]; then
echo "solr is running at pid: " $pid

else
echo "solr not running."
fi
}

case "$1" in

start)

start
;;

stop)

stop
;;

restart)

stop
start
;;

status)

status
;;

*)

echo $"Usage: $0 {start|stop|restart}"
;;

esac
