solr: Improved init script

This commit is contained in:
Ossi Salmi 2013-12-13 00:47:42 +02:00
parent 8276a8cc30
commit 0472e6b08e
2 changed files with 43 additions and 23 deletions

View file

@ -137,9 +137,10 @@ class solr {
}
service { "solr":
ensure => running,
enable => true,
hasstatus => true,
ensure => running,
enable => true,
hasstatus => true,
hasrestart => true,
}
file { "/etc/solr":

View file

@ -48,51 +48,70 @@ if [ ! -e "${HOMEDIR}/solr.xml" ]; then
exit 1
fi
start_solr() {
# Check to see if Solr is running
do_status() {
pgrep -u ${SOLRUSER} -f start.jar >/dev/null
RUNNING=$?
if [ $RUNNING -eq 0 ]; then
echo "[FAILED]"
echo
echo "Reason: Solr already running"
}
do_start() {
echo -n "Starting Solr... "
# Check to see if Solr is running
do_status
if [ $? -eq 0 ]; then
echo "failed. Solr already running."
exit 1
fi
# Start Solr
echo "Starting Solr"
COMMAND="java -Djetty.host=127.0.0.1 -Dlog4j.configuration=${LOG4JCONFIG} -Dsolr.solr.home=${HOMEDIR} ${MEMORYLIMIT} -jar start.jar > /dev/null &"
su -s /bin/sh - ${SOLRUSER} -c "umask 007; cd ${RUNDIR}; ${COMMAND}"
if [ $? -eq 0 ]; then
echo "done."
else
echo "failed."
exit 1
fi
}
stop_solr() {
echo -n "Stopping Solr: "
do_stop() {
echo -n "Stopping Solr... "
pkill -u ${SOLRUSER} -f start.jar
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo "Success"
if [ $? -ne 0 ]; then
echo "not running."
else
echo "Failed"
for seq in 1 2 3 4 5 6 7 8 9 10; do
do_status
if [ $? -ne 0 ]; then
success=1
break
fi
sleep 1
done
if [ -n "${success}" ]; then
echo "done."
else
echo "failed."
exit 1
fi
fi
}
case "$1" in
start)
start_solr
do_start
;;
stop)
stop_solr
do_stop
;;
restart)
stop_solr
sleep 2
start_solr
do_stop
do_start
;;
status)
pgrep -u ${SOLRUSER} -f start.jar >/dev/null
do_status
exit $?
;;