#!/bin/sh
#
# Startup for transd
#

KINIT=/ecat/krb5/bin/kinit
HOSTNAME=`/usr/bin/uname -n`
DOMAIN=mit.edu
REALM=ATHENA.MIT.EDU
export KINIT HOSTNAME DOMAIN REALM

TRANSD=/ecat/transd
PROFILE=/ecat/profile
SPROFILE=/ecat/sprofile
HTTPD=/ecat/httpd
export TRANSD PROFILE SPROFILE HTTPD

case "$1" in
'start')
        $KINIT -k ecat/$HOSTNAME.$DOMAIN\@$REALM
        if [ -f $TRANSD/transd ]; then
                cd $TRANSD
		./transd
                echo "transd"
        fi
        if [ -f $PROFILE/profiled ]; then
                cd $PROFILE
		./profiled
                echo "profiled"
        fi
        if [ -f $SPROFILE/sprofiled ]; then
                cd $SPROFILE
		./sprofiled
                echo "sprofiled"
        fi
        if [ -f $HTTPD/httpd ]; then
		cd $HTTPD
                ./httpd -d .
                echo "httpd"
        fi
        ;;
'stop')
        PID=`ps -ef | awk '{if ($NF~/(^|\/)transd$/) print $2}'`
        if [ ! -z "$PID" ] ;  then
                /usr/bin/kill ${PID} 1> /dev/null 2>&1
        fi
        PID=`ps -ef | awk '{if ($NF~/(^|\/)profiled$/) print $2}'`
        if [ ! -z "$PID" ] ;  then
                /usr/bin/kill ${PID} 1> /dev/null 2>&1
        fi
        PID=`ps -ef | awk '{if ($NF~/(^|\/)sprofiled$/) print $2}'`
        if [ ! -z "$PID" ] ;  then
                /usr/bin/kill ${PID} 1> /dev/null 2>&1
        fi
        PID=`/usr/bin/cat $HTTPD/logs/httpd.pid`
        if [ ! -z "$PID" ] ;  then
                /usr/bin/kill ${PID} 1> /dev/null 2>&1
        fi
        ;;
*)
        echo "Usage: $0 { start | stop }"
        ;;
esac
exit 0
