像守护进程一样运行solr

时间:2015-01-08 02:20:41

标签: bash solr init.d

我尝试让solr作为/etc/init.d/solr中的启动脚本运行。 这是我从How to start Solr automatically?

复制的脚本
#!/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.

# Comments to support chkconfig on Red Hat Linux
# chkconfig: 2345 64 36
# Description: A very fast and reliable search engine.
# processname solr

# Source function library.
. /etc/init.d/functions

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

我按照上面的链接做了所有事情。但是得到一个错误

service solr start
Starting solr.../etc/init.d/solr: Usage: daemon [+/-nicelevel] {program}
failed. See error code for more information.

阅读https://blog.hazrulnizam.com/create-init-script-centos-6/我不明白为什么守护进程被写错了

1 个答案:

答案 0 :(得分:0)

这不起作用,因为daemon函数(来自/etc/init.d/functions)自2010年(发布脚本时)发生了更改,并且不再接受相同的参数。您需要重写daemon行以接受当前支持的参数。

我查看了CentOS 6盒子上的daemon功能,看起来你可以替换这一行:

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

只有这个:

daemon "java -jar /usr/local/solr/example/start.jar"

(假设solr)中安装了/usr/local/solr/example