2

I would like to run solr with daemon. I saw in another post there is a init.d script you can run but it seems to have problems in my ubuntu environment. whenever i try to run the script with /etc/init.d/solr start or when i try to run the below line manually:

daemon java -jar start.jar 

it errors:

daemon: invalid option -- 'j'

Any ideas? thx.

prostock
  • 9,327
  • 19
  • 70
  • 118

3 Answers3

8

Below is a working script for daemonizing Solr. Couple important notes here:

  1. You need to set the chdir for the daemon script or else you'll get errors loading your config file.
  2. This will allow you to start/stop/status/restart Solr.
  3. This is a simple version that seems to be working for me.

Here's the script:

#!/bin/sh

# Prerequisites:
# 1. Solr needs to be installed at /usr/local/solr/example
# 2. daemon needs to be installed
# 3. Script needs to be executed by root

# This script will launch Solr in a mode that will automatically respawn if it
# crashes. Output will be sent to /var/log/solr/solr.log. A pid file will be 
# created in the standard location.

start () {
    echo -n "Starting solr..."

    # start daemon
    daemon --chdir='/usr/local/solr/example' --command "java -jar start.jar" --respawn --output=/var/log/solr/solr.log --name=solr --verbose

    RETVAL=$?
    if [ $RETVAL = 0 ]
    then
        echo "done."
    else
        echo "failed. See error code for more information."
    fi
    return $RETVAL
}

stop () {
    # stop daemon
    echo -n "Stopping solr..."

    daemon --stop --name=solr  --verbose
    RETVAL=$?

    if [ $RETVAL = 0 ]
    then
        echo "done."
    else
        echo "failed. See error code for more information."
    fi
    return $RETVAL
}


restart () {
    daemon --restart --name=solr  --verbose
}


status () {
    # report on the status of the daemon
    daemon --running --verbose --name=solr
    return $?
}


case "$1" in
    start)
        start
    ;;
    status)
        status
    ;;
    stop)
        stop
    ;;
    restart)
        restart
    ;;
    *)
        echo $"Usage: solr {start|status|stop|restart}"
        exit 3
    ;;
esac

exit $RETVAL
mlissner
  • 17,359
  • 18
  • 106
  • 169
  • 1
    does you know how can I install daemon on a CentOS box? – Ruben Trancoso May 24 '12 at 09:40
  • Also - Just wanted to point out I can run this as a non-root user with no problems. Just had to do CHOWN -R myuser on the DATA directory in the Solr directory – someuser Apr 28 '13 at 12:25
  • 3
    **daemon** does not come installed on some Debian system. `sudo apt-get install daemon` should resolve such issues. – earthmeLon Jul 17 '13 at 21:59
1

See:

Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
-1

Try this:

daemon `java -jar start.jar` 
nrph
  • 335
  • 7
  • 18