1

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.

JakeRow123
  • 135
  • 1
  • 2
  • 4

3 Answers3

2

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.

Wesley
  • 32,320
  • 9
  • 80
  • 116
  • 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 04:31
  • @JakeRow123 `jobs` should be a bash builtin, not a package. What is the result of running `echo $SHELL`? – Wesley Apr 21 '12 at 04:38
  • result is "/bin/bash", according to this post: http://superuser.com/questions/152767/ubuntu-10-04-lts-jobs-command-not-working, "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 04: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 05:06
0

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

user105566
  • 29
  • 1
  • 5
0

I got that from lucidWorks/app/bin/stop.sh, I hope it works for you

#!/usr/bin/env bash

# You can override pass the following parameters to this script:
# -lwe_app_dir -lwe_data_dir -lwe_conf_dir -lwe_log_dir

JVM="java"

# Find location of this script and go up a level to lucidworksAppHome

sdir="`dirname \"$0\"`"


# Stop the processes

$JVM -jar "$sdir/StartUtil.jar" -jvm_cmd $JVM ${1+"$@"} stop
Amr Lotfy
  • 101
  • 2