Created
September 29, 2013 20:51
-
-
Save vumaasha/6756423 to your computer and use it in GitHub Desktop.
Installing solr on jetty 9. Downloads jetty and solr from the given urls and installs the sample core collection1 in solr in jetty 9. Also creates a use for jetty and installs jetty as a service. *Run the script as super user or using sudo in ubuntu.*
This file contains hidden or 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
#!/bin/sh | |
# set the configuration variables below, before running the script | |
# get the solr nightly build download link from https://builds.apache.org/job/Solr-Artifacts-4.x/lastSuccessfulBuild/artifact/solr/package/ | |
JETTY_URL="http://eclipse.org/downloads/download.php?file=/jetty/stable-9/dist/jetty-distribution-9.0.5.v20130815.tar.gz&r=1" | |
JETTY_HOME="/opt/jetty" | |
JAVA='/usr/local/jdk1.7.0_09/bin/java' | |
JETTY_PORT=8085 | |
JETTY_HOST=127.0.0.1 | |
SOLR_URL="https://builds.apache.org/job/Solr-Artifacts-4.x/lastSuccessfulBuild/artifact/solr/package/solr-4.6-2013-09-29_16-22-46.tgz" | |
SOLR_HOME="/opt/solr" | |
JAVA_OPTIONS="-Xms16M -Xmx64M -XX:MaxPermSize=32M" | |
while getopts ":ir" opt; do | |
case $opt in | |
i)install=1;; | |
r)remove=1;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
;; | |
esac | |
done | |
check_for_error() { | |
if [ $? -ne 0 ]; then | |
echo $1 | |
exit 2 | |
fi | |
} | |
if [ ! -z $install ]; then | |
echo "installing solr in jetty..." | |
#download jetty | |
cd /tmp | |
mkdir jetty | |
cd jetty | |
wget "$JETTY_URL" | |
mv download* jetty.tar.gz | |
tar -xvf jetty.tar.gz | |
mv jetty-distribution* jetty | |
# create jetty home if does not exist | |
if [ ! -d $JETTY_HOME ]; then | |
mkdir $JETTY_HOME | |
check_for_error "unable to create jetty home. exiting.." | |
fi | |
cp -r jetty/* $JETTY_HOME | |
# add a jetty user if not exists | |
grep -q ^jetty /etc/passwd | |
if [ $? -ne 0 ]; then | |
useradd jetty -U -s /bin/false | |
check_for_error "unable to add jetty user. exiting.." | |
fi | |
chown -R jetty:jetty $JETTY_HOME | |
# create jetty configuration | |
cp $JETTY_HOME/bin/jetty.sh /etc/init.d/jetty | |
echo "JAVA=$JAVA" > /etc/default/jetty | |
echo "JETTY_HOME=$JETTY_HOME" >> /etc/default/jetty | |
echo "JETTY_HOST=$JETTY_HOST" >> /etc/default/jetty | |
echo "JETTY_ARGS=jetty.port=$JETTY_PORT" >> /etc/default/jetty | |
echo "JETTY_USER=jetty" >> /etc/default/jetty | |
# starting jetty service | |
service jetty start | |
service jetty check | |
# registering jetty service to start on boot automatically | |
update-rc.d jetty defaults | |
# remove unsecure content demo apps | |
cd $JETTY_HOME/webapps | |
rm -rf test.d/ test.war test.xml async-rest.war | |
cd $JETTY_HOME | |
rm -rf webapps.demo | |
# installing solr | |
mkdir /tmp/solr | |
cd /tmp/solr | |
wget $SOLR_URL | |
tar -xvf solr-4.* | |
cd solr-4.* | |
# create solr home if not exists | |
if [ ! -d $SOLR_HOME ]; then | |
mkdir $SOLR_HOME | |
check_for_error "Unable to create solr home. exiting..." | |
fi | |
cp dist/solr-4.*war $JETTY_HOME/webapps/solr.war | |
cp example/lib/ext/* $JETTY_HOME/lib/ext | |
mkdir $SOLR_HOME/cores | |
mkdir $SOLR_HOME/cores/production | |
cp -r example/solr/* $SOLR_HOME/cores/production | |
cp -r dist $SOLR_HOME | |
cp -r contrib $SOLR_HOME | |
echo JAVA_OPTIONS='"-Dsolr.solr.home='$SOLR_HOME'/cores/production '$JAVA_OPTIONS'"' >> /etc/default/jetty | |
chown -R jetty:jetty $SOLR_HOME | |
service jetty restart | |
#clean up tempfiles | |
rm -rf /tmp/jetty | |
rm -rf /tmp/solr | |
echo "Status of jetty....." | |
service jetty check | |
exit 0 | |
elif [ ! -z $remove ]; then | |
echo "unistallting solr and jetty..." | |
service jetty stop | |
update-rc.d -f jetty remove | |
cd $JETTY_HOME | |
rm -rf * | |
cd $SOLR_HOME | |
rm -rf * | |
exit 0 | |
fi | |
cat << EOF | |
Usage: | |
-i = install | |
-r = uninstall | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On ubuntu 12.10 I had to create this dir: mkdir -p /var/cache/jetty/data before installing jetty and solr with this script, then it worked. Many thanks.