Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I used to start Solr with this command:

java -jar start.jar

and all I had to do to stop it was press Control + C

But then I started it this way:

java -jar start.jar &

Which starts it as a background process so I can get the shell back after it starts. But now I don't know how to stop it. I am using Ubuntu Server.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You started the process and put it in the background. List background processes with the jobs command.

To bring background processes to the foreground, use fg [job number]. From there, you can exit them as normal.


EDIT 1

In light of new information, the problem has nothing to do with foreground and background processes. Apparently the process is being started in the background, and then the terminal window is being closed. Thus, it's not a job attached to the terminal anymore.

In this case, you simply kill the process associated with Solr. Use ps to find the process and kill to stop it.

share|improve this answer
    
I don't have the "jobs" command, do you know the package name so I install is via apt-get? "sudo apt-get install jobs" didn't work. –  JakeRow123 Apr 21 '12 at 4:31
    
@JakeRow123 jobs should be a bash builtin, not a package. What is the result of running echo $SHELL? –  Wesley Apr 21 '12 at 4:38
    
result is "/bin/bash", according to this post: superuser.com/questions/152767/…, "jobs displays the status of jobs in the current session". I started Solr inside vmware a few days ago from another terminal window than the one I am working in atm. So maybe that's why it doesn't display anything. I tried "ps -e" which shows several "jetty" processes but when I try to bring them to the foreground using fg [their job number], it just says "no such jobs". Solr runs via jetty so I figured stopping that would stop Solr. –  JakeRow123 Apr 21 '12 at 4:45
    
killing the jetty services didn't work, after killing them and doing another ps -e command, they showed up again. But killing the java service did stop solr. Don't think this is the proper way but it will do for now. Thanks. –  JakeRow123 Apr 21 '12 at 5:06

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.