#!/bin/sh
USERNAME=''
PASSWD=''

SERVICE='telecom_fyoung'
SERVICE_START="/etc/storage/bin/telecom_fyoung -u $USERNAME -p $PASSWD -i 60 -s online -l 4 -d"
SERVICE_STOP="/etc/storage/bin/telecom_fyoung -u $USERNAME -p $PASSWD -i 60 -s offline -l 4"
SERVICE_TEST="/etc/storage/bin/telecom_fyoung -u $USERNAME -p $PASSWD -i 10 -s online -l 4"

IS_TEST=0

if [ $# == 1 ] && [ "$1" == "-t" ]; then
    IS_TEST=1
fi
 
if pgrep $SERVICE > /dev/null
then
    echo "$SERVICE service running, everything is fine"
else
    if [ "$IS_TEST" == "1" ]; then
        $SERVICE_TEST
        exit
    fi
    echo "$SERVICE is not running"
    echo "try to start $SERVICE"
    $SERVICE_STOP
    $SERVICE_START
    if [ "$?" == "0"] ; then
        echo "$SERVICE started success."
    else
        echo "$SERVICE fail to start."
    fi
fi
