Skip to content

Instantly share code, notes, and snippets.

@iamsortiz
Created January 27, 2016 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamsortiz/b95fcfe1baa547b4d4fd to your computer and use it in GitHub Desktop.
Save iamsortiz/b95fcfe1baa547b4d4fd to your computer and use it in GitHub Desktop.
SOLR local deploy utils
##########################################################
#
# The MIT License (MIT)
#
# Copyright (c) 2015 Samuel Ortiz Reina (@iamsortiz)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
##########################################################
#
# 1. "Installing" the script
#
# Option 1: Append to ~/.bashrc (by copypaste)
# Option 2: Download the file and include it in .bashrc with "source solr.sh" (this way is auto included every time)
# Option 3: Download the file and include it in your terminal with "source solr.sh" (this way is included only for that terminal)
#
# 2. Usage
#
# $ my_solr_install
# Downloads and untars SOLR into ~/.my_services
#
# $ my_solr_start
# Starts SOLR
#
# $ my_solr_stop
# Stops SOLR
#
# $ my_solr_status
# Checks if SOLR is running
#
###########################################################
################
# CONFIG - START
################
MY_SERVICES_HOME=$HOME/.my_services
MY_SOLR_VERSION=5.4.1
################
# CONFIG - END
################
MY_SOLR_BINARY_NAME=solr-$MY_SOLR_VERSION
MY_SOLR_BINARY_URL=http://apache.rediris.es/lucene/solr/$MY_SOLR_VERSION/$MY_SOLR_BINARY_NAME.tgz
MY_SOLR_HOME=$MY_SERVICES_HOME/$MY_SOLR_BINARY_NAME
alias solr=$MY_SOLR_HOME/bin/solr
alias my_solr_start='solr start'
my_solr_stop () {
echo 'SOLR - Stopping'
#Kills process listening at default SOLR port
fuser -k 8983/tcp > /dev/null 2> /dev/null
echo -e '\t[STOPED] SOLR'
sleep 1
my_solr_status
}
my_solr_status () {
SOLR_PORT=8983
SOLR_PORT_TEST=$(netstat -nlp 2> /dev/null | grep -o $SOLR_PORT)
echo 'SOLR - Checking status'
if [[ $SOLR_PORT == $SOLR_PORT_TEST ]];
then
echo -e "\t[RUNNING] Port $SOLR_PORT in use. Assuming SOLR is running"
SOLR_PID=$(netstat -nlp 2> /dev/null | grep -e "$SOLR_PORT" | grep -oe '\w*/java'| awk -F '/' '{print $1}')
echo -e "\t\tPID: $SOLR_PID"
SOLR_CWD=$(pwdx $SOLR_PID | awk '{print $2}')
echo -e "\t\tCWD: $SOLR_CWD"
else
echo -e "\t[STOPED] Port $SOLR_PORT not in use. Assuming SOLR is stoped"
fi
}
my_solr_install () {
mkdir -p $MY_SERVICES_HOME
curl $MY_SOLR_BINARY_URL | tar xvz -C $MY_SERVICES_HOME
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment