#!/bin/bash # $Id$ # skydaemon.rc - control the tasks managed by the skymasterd PREFIX=`Defaults read NSGlobalDomain SxDefaultNamespacePrefix` NAMESPACE="$PREFIX.master" if [ -n "$2" ] then case $2 in 'start') sh -c "sxc_call $NAMESPACE tasks 1>/dev/null 2>&1" if [ $? -eq 2 ] then echo "no matching component found (can't connect to registry)" exit fi printf "%-50s\n" "Starting task $1" echo -n "login : " TMPPID=`sh -c "sxc_call $NAMESPACE start $1" 2>/dev/null` RESULT=$? PID=`echo $TMPPID | sed s/login:// -` if [ "x$RESULT" = "x3" ]; then echo "Invalid credentials." exit else if [ $PID == "0" ] then echo "FAILED" else echo "started (pid: $PID)" fi fi ;; 'stop') sh -c "sxc_call $NAMESPACE tasks 1>/dev/null 2>&1" if [ $? -eq 2 ] then echo "no matching component found (can't connect to registry)" exit fi printf "%-50s\n" "Stopping task $1" echo -n "login : " sh -c "sxc_call $NAMESPACE stop $1 1>/dev/null 2>&1" RESULT=$? if [ "x$RESULT" = "x3" ]; then echo "Invalid credentials." exit else if [ $RESULT == 0 ] then echo "OK" else echo "FAILED" fi fi ;; 'restart') sh -c "sxc_call $NAMESPACE tasks 1>/dev/null 2>&1" if [ $? -eq 2 ] then echo "no matching component found (can't connect to registry)" exit fi printf "%-50s\n" "Restarting task $1" echo -n "login : " TMPPID=`sh -c "sxc_call $NAMESPACE restart $1" 2>/dev/null` if [ "x$?" = "x3" ]; then echo "Invalid credentials." exit fi PID=`echo $TMPPID | sed s/login:// -` if [ $PID == 0 ]; then echo "FAILED" else echo "started (pid: $PID)" fi ;; 'instances') sh -c "sxc_call $NAMESPACE tasks 1>/dev/null 2>&1" if [ $? -eq 2 ] then echo "no matching component found (can't connect to registry)" exit fi echo -n "login : " INSTANCES=`sh -c "sxc_call $NAMESPACE instances $1"` INSTANCES=`echo $INSTANCES | sed s/login:// -` for instance in $INSTANCES do echo $instance done ;; 'reload') echo "This command isn't yet supported" exit printf "%-50s\n" "Reloading config of task $1" echo -n "login : " TMPPID=`sh -c "sxc_call $NAMESPACE reload $1"` PID=`echo $TMPPID | sed s/login:// -` if [ $PID == "0" ] then echo "FAILED" else echo "OK" fi ;; 'status') sh -c "sxc_call $NAMESPACE tasks 1>/dev/null 2>&1" if [ $? -eq 2 ] then echo "no matching component found (can't connect to registry)" exit fi printf "%-50s" "Status of task $1" STATUS=`sh -c "sxc_call $NAMESPACE isRunning $1"` if [ $STATUS == "0" ] then echo "not running" else echo "running" fi ;; *) echo echo "SKYRiX masterd task control .rc script" echo echo "usage: $0