#!/bin/bash

. /etc/init.d/functions

LOG_FILE=/var/log/fofb-opcua-server.log
LOCK_FILE=/var/lock/subsys/fofb-opcua-server.log

# Start the service
start() {
    if [ -f $LOCK_FILE ]; then
        echo "fofb-opcua server already running"
        exit 1
    fi

    echo "Starting fofb-opcua-server" >> $LOG_FILE
    cd /opt/fofb/opcua-server
    stdbuf -oL opcua-generic-chimeratk-server01 &>> $LOG_FILE &

    ### Create the lock file ###
    touch $LOCK_FILE
    success $"fofb-opcua server startup"
}


# Restart the service
stop() {
    echo "Stopping fofb-opcua-server" >> $LOG_FILE
    killproc opcua-generic-chimeratk-server01
    ### Now, delete the lock file ###
    rm -f $LOCK_FILE
}

### main logic ###
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status opcua-generic-chimeratk-server01
        ;;
    restart|reload|condrestart)
        stop
        start
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit 0



