
Tengo un script TCL en CentOS 6.5 que ejecuto desde el shell, como root, sin problemas. Pero si lo ejecuto como un servicio desde init.d falla. Aquí está el script 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
Y aquí está el mensaje de error que recibo:
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)
Parece que TCL no puede ejecutar dorpc, pero este puerto definitivamente está abierto; puedo ejecutar el script desde el shell inmediatamente después de que falla aquí y funciona bien. Creo que tengo configuradas todas las variables de entorno relevantes que veo en printenv como raíz (tiene el mismo error con o sin las variables de entorno configuradas en el script init.d).
¿Hay algo sobre init.d y TCL que me falta?
Respuesta1
Mi amigo me ayudó a resolver esto: usamos bash -l -c para obtener un shell de inicio de sesión completo para ejecutar el script TCL, y aparentemente esto le gustó mucho más:
start() {
echo -n "Starting $prog: "
/bin/bash -l -c '/opt/camelot/register-phones.sh'
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCKFILE
echo
return $RETVAL
}