2015-01-08 206 views
1

我嘗試使solr在/etc/init.d/solr中作爲啓動腳本運行。 這是劇本,我從How to start Solr automatically?像守護進程運行solr

#!/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 

我所做的一切copypasted在上面的鏈接描述。但得到一個錯誤

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/我不明白爲什麼守護寫不正確

回答

0

這不是工作,因爲2010年以來daemon功能(從/etc/init.d/functions)已經改變(腳本被張貼時)並不再接受相同的參數。您將需要重寫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中)。