Create a deamon, mondify the paths according to your needs.
enter code here
Steps to install SOLR as a daemon
create /etc/init.d/solr.production and copy the below contents into the file. Please change all necessary paths.
change directory to /etc/init.d
run sudo /sbin/chkconfig --add solr.production
run sudo /sbin/service solr.production start
run ps -Af | grep start.jar to check that it is running
run cat /var/run/solr.production.pid (change path if needed) to see if PID value is correct.
/etc/init.d/solr.production
#!/bin/bash
# chkconfig: 2345 98 02
# description: Starts and stops Solr production
# source function library
. /etc/rc.d/init.d/functions
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
SOLR_HOME=/var/apps/solr
PIDFILE=/var/run/solr.production.pid
START_COMMAND="/usr/lib/jdk1.6.0_03/bin/java -Xms512M -Xmx1024M -jar start.jar"
LOG_FILE="$SOLR_HOME/logs/console.log"
NAME="Solr (production)"
start() {
echo -n "Starting $NAME"
if [ -f $PIDFILE ]; then
echo -n "$PIDFILE exists. $NAME may be running."
else
cd $SOLR_HOME
$START_COMMAND 2 > $LOG_FILE &
sleep 2
echo `ps -ef | grep -v grep | grep "$START_COMMAND" | awk '{print $2}'` > $PIDFILE
echo "Done"
fi
return 0
}
stop() {
echo -n "Stopping $NAME"
kill `cat $PIDFILE`
rm $PIDFILE
echo "Done"
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 5
start
;;
*)
echo "Usage: $0 (start | stop | restart)"
exit 1
esac
exit $?
Now you can use /etc/init.d/solr stop|start|restart