#!/bin/sh

if test -z $1
then
    echo "ccc.sh:  PPDS to WEBSOCKET crossconnector control"
    echo "Usage: ccc.sh [start stop status]"
    echo
fi

if test "$1" = "start"
then
    status=`ps -ef | grep "wsccppds.py" | grep -v gre`
    if test "$status" = ""
    then
        ./wsccppds.py -p 12000 -w 9998 -i IO > /dev/null 2>&1 &
        ./wsccppds.py -p 8000 -w 9999 -i CAE > /dev/null 2>&1 &
        echo "WS to PPDS crossconnectors have started"
    else
        echo "WS to PPDS crossconnectors are running at now" 
    fi
fi
if test "$1" = "stop"
then
    status=`ps -ef | grep "wsccppds.py" | grep -v gre`
    if test "$status" = ""
    then
        echo "WS to PPDS crossconnectors do not run now"
    else
        pid=`ps -ef | grep "wsccppds.py" | grep -v gre | awk '{print $2}'`
        kill $pid
        echo "WS to PPDS crossconnectors have stopped"
    fi
fi
if test "$1" = "status"
then
    status=`ps -ef | grep "wsccppds.py" | grep -v gre`
    if test "$status" = ""
    then
        echo "WS to PPDS crossconnectors are not running at now"
    else
        echo "WS to PPDS crossconnectors are running at now:"
        ps -ef | grep "wsccppds.py" | grep -v gre
    fi
fi
