puppet/solr/templates/solr.init.erb
2013-12-13 00:47:53 +02:00

124 lines
2.5 KiB
Text

<%
mem, unit = @memorysize.split
case unit
when "GB"
mem = mem.to_i * 1024
else
mem = mem.to_i
end
heapmin = (mem * 0.15).to_i
heapmax = (mem * 0.85).to_i
-%>
#!/bin/sh
# chkconfig: 2345 95 05
# description: Solr Server
# processname: solr
### BEGIN INIT INFO
# Provides: solr
# Required-Start: $local_fs $network $syslog
# Should-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Solr server
# Description: Solr server
### END INIT INFO
SOLRUSER="solr"
RUNDIR="/srv/solr/run"
HOMEDIR="/srv/solr/cores"
LOG4JCONFIG="file:///${RUNDIR}/resources/log4j.properties"
MEMORYLIMIT="-Xms<%= heapmin %>M -Xmx<%= heapmax %>M"
if [ `id -u` != "0" ]; then
echo "This script must be run with root privileges." && exit 1
fi
if [ ! -e "${RUNDIR}/start.jar" ]; then
echo "Failed to find Solr jar file: ${RUNDIR}/start.jar"
echo "Check /etc/init.d/solr file for correct settings."
exit 1
fi
if [ ! -e "${HOMEDIR}/solr.xml" ]; then
echo "Failed to find Solr config files: ${HOMEDIR}/solr.xml"
echo "Check /etc/init.d/solr file for correct settings."
exit 1
fi
do_status() {
pgrep -u ${SOLRUSER} -f start.jar >/dev/null
}
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
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
}
do_stop() {
echo -n "Stopping Solr... "
pkill -u ${SOLRUSER} -f start.jar
if [ $? -ne 0 ]; then
echo "not running."
else
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)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
status)
do_status
exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0