#!/bin/sh

# Read config file if it is present.
if [ -r /etc/default/comtraded ]
then
    . /etc/default/comtraded
fi

start() {
    if [ "$MOUNT_SD" = "yes" ]; then
        /usr/local/bin/comtrade/comtradeSDCardHotplug.sh &> /dev/null &
    else
        /usr/local/bin/comtrade/StartComtrade &> /dev/null &    
    fi
}	
stop() {
    busybox killall -9 comtradeSsh.sh
    busybox killall -9 comtradeSDCardHotplug.sh
    busybox killall -9 StartComtrade
    busybox killall -9 comtradeWorker.sh
    busybox killall -9 IEC61850FileClient
    if [ "$MOUNT_SD" = "yes" ]; then
        sync
        umount /mnt
    fi
}
restart() {
    stop
    start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload)
    restart
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart}"
    exit 1
esac

exit $?
