0

I have a TCL script in CentOS 6.5 that I run from shell, as root, with no problems. But if I run it as a service from init.d it fails. Here is the init.d script:

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

And here is the error message I get:

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)

It seems like TCL fails to run dorpc, but this port is definitely open - I can run the script from shell right after it fails here and it works just fine. I believe I have all the relevant environment variables set that I see from printenv as root (it has the same error with or without the environment variables being set in the init.d script).

Is there something about init.d and TCL that I'm missing?

1
  • Are you sure that you start the server before you try to run the script? – Johannes Kuhn Oct 3 '16 at 7:58
0

My friend helped me figure this one out - we used bash -l -c to get a full login shell for the TCL script to run in, and it apparently liked this much better:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.