CentOS - TCL 腳本可以在 shell 中運行,但在 init.d 中失敗

CentOS - TCL 腳本可以在 shell 中運行,但在 init.d 中失敗

我在 CentOS 6.5 中有一個 TCL 腳本,我以 root 身分從 shell 運行,沒有任何問題。但如果我將它作為 init.d 的服務運行,它就會失敗。這是 init.d 腳本:

#!/bin/bash
#
# camelot    Camelot 11.5.0
#

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

# Source networking configuration.
. /etc/sysconfig/network

PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
CAMELOT_LOGS=/var/camelot/logs
CAMELOT_LIB=/usr/local/camelot/lib
RETVAL=0
prog="camelot"
LOCKFILE=/var/lock/subsys/$prog

# Declare variables for service

start() {
    echo -n "Starting $prog: "
    /opt/camelot/register-phones.sh
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch $LOCKFILE
    echo
    return $RETVAL
}

stop() {
    echo -n "Shutting down $prog: "
    killall screen
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
    echo
    return $RETVAL
}

status() {
    echo -n "Checking $prog status: "
    echo -n "Sorry, not implemented yet. run 'screen -r' to check on the process."
    RETVAL=$?
    return $RETVAL
}

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

這是我收到的錯誤訊息:

Starting camelot: camelot server at localhost:6060 is inaccessible
    while executing
"error "camelot server at $server:$port is inaccessible""
    (procedure "dorpc" line 122)
    invoked from within
"dorpc $server $port $outmsg"
    (procedure "createendpoint" line 7)
    invoked from within
"createendpoint $server $port 0 "$type $args@""
    (procedure "camelot::newendpoint" line 10)
    invoked from within
"camelot::newendpoint $CamelotServerIp $CamelotServerPort sipx SEP$ep2MAC"
    (procedure "registerPhone" line 22)
    invoked from within
"registerPhone $data"
    ("while" body line 3)
    invoked from within
"while {$data != ""} {
     # puts $data
     puts [registerPhone $data]
     gets $fp data
 }"
    (file "/opt/camelot/register-phones.sh" line 7)

看起來 TCL 無法運行 dorpc,但這個連接埠肯定是打開的 - 我可以在此處失敗後立即從 shell 運行該腳本,並且運行得很好。我相信我已經設定了從 printenv 作為 root 看到的所有相關環境變數(無論是否在 init.d 腳本中設定環境變量,它都會出現相同的錯誤)。

關於 init.d 和 TCL 有什麼我遺漏的嗎?

答案1

我的朋友幫我解決了這個問題 - 我們使用 bash -l -c 來獲得一個完整的登入 shell 來運行 TCL 腳本,它顯然更喜歡這樣:

start() {
    echo -n "Starting $prog: "
    /bin/bash -l -c '/opt/camelot/register-phones.sh'
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch $LOCKFILE
    echo
    return $RETVAL
}

相關內容