Created
June 18, 2012 12:51
-
-
Save henriquemoody/2948238 to your computer and use it in GitHub Desktop.
Run Solr as daemon
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
#!/usr/bin/env bash | |
SOLR_RUNNING=0 | |
SOLR_DIRECTORY="/usr/local/solr" | |
SOLR_LOG="${SOLR_DIRECTORY}/logs/solrd.log" | |
SOLR_LOCK="${SOLR_DIRECTORY}/solrd.pid" | |
touch "${SOLR_LOCK}" | |
SOLR_PID=$(cat ${SOLR_LOCK}) | |
let SOLR_PID=SOLR_PID+0 | |
touch "${SOLR_LOG}" | |
chmod 0777 "${SOLR_LOG}" | |
solr_check() | |
{ | |
if [ "${SOLR_PID}" -gt 0 ] && [ $(ps -p ${SOLR_PID} | wc -l) -eq 2 ] | |
then | |
SOLR_RUNNING=1 | |
else | |
SOLR_RUNNING=0 | |
fi | |
} | |
solr_status() | |
{ | |
solr_check | |
if [ ${SOLR_RUNNING} -eq 1 ] | |
then | |
echo "Solr is running with the PID ${SOLR_PID}" | |
else | |
echo "Solr is not running" | |
fi | |
} | |
solr_start() | |
{ | |
solr_check | |
if [ ${SOLR_RUNNING} -eq 0 ] | |
then | |
cd "${SOLR_DIRECTORY}" | |
java -Dsolr.solr.home=. -jar start.jar > "${SOLR_LOG}" 2>&1 & | |
SOLR_PID="$!" | |
echo "${SOLR_PID}" > "${SOLR_LOCK}" | |
echo "Starting Solr with the PID ${SOLR_PID}" | |
else | |
echo "Solr is already running with the PID ${SOLR_PID}" | |
fi | |
} | |
solr_stop() | |
{ | |
solr_check | |
if [ ${SOLR_RUNNING} -eq 1 ] | |
then | |
echo "Stopping Solr (PID ${SOLR_PID})" | |
kill -KILL ${SOLR_PID} | |
:>"${SOLR_LOCK}" | |
else | |
echo "Solr is not running" | |
fi | |
} | |
case ${1} in | |
start) | |
solr_start | |
exit 0 | |
;; | |
stop) | |
solr_stop | |
exit 0 | |
;; | |
restart) | |
solr_stop | |
solr_start | |
exit 0 | |
;; | |
status) | |
solr_status | |
exit 0 | |
;; | |
*) | |
echo "Usage: ${0} {start|stop|restart|status}" 1>&2 | |
exit 2 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment