Skip to content

Instantly share code, notes, and snippets.

@ambroisemaupate
Created September 1, 2014 16:50
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 ambroisemaupate/a888ae6134e58e36ad7d to your computer and use it in GitHub Desktop.
Save ambroisemaupate/a888ae6134e58e36ad7d to your computer and use it in GitHub Desktop.
Solr launch script
#!/bin/sh
### BEGIN INIT INFO
# Provides: solr
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Solr indexing server
### END INIT INFO
# Put this into your init.d server folder (for example: /etc/init.d/solr)
# Do not forget to give it the execute flag and to do `update-rc.d solr defaults`
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Solr indexing server"
NAME=solr
SOLR_HOME=/opt/solr/myproject
DAEMON=$SOLR_HOME/$NAME.sh
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
# Read config file if it is present.
if [ -r /etc/default/$NAME ]
then
. /etc/default/$NAME
fi
#
# Function that starts the daemon/service.
#
d_start() {
start-stop-daemon --start --pidfile $PIDFILE \
--chdir $SOLR_HOME --background --make-pidfile \
--exec $DAEMON
}
#
# Function that stops the daemon/service.
#
d_stop() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--name java
rm -f $PIDFILE
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
restart|force-reload)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
#!/bin/bash
# Put this into your solr server folder (for example: /opt/solr/myproject/solr.sh)
# Do not forget to give it the execute flag
for JAVA in "$JAVA_HOME/bin/java" "/usr/bin/java" "/usr/local/bin/java"
do
if [ -x $JAVA ]
then
break
fi
done
if [ ! -x $JAVA ]
then
echo "Unable to locate java. Please set JAVA_HOME environment variable."
exit
fi
# start solr
exec $JAVA -jar start.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment