#!/bin/bash

WFCWorkDir=/opt/wfc
DockerDir=${WFCWorkDir}/docker/license-server
DockerCompose=docker-compose
PIDFile=/run/licensecontrol.pid

case "$1" in
    start)
        cd ${DockerDir}
        if [ -z "$2" ]; then
            ${DockerCompose} up -d 
            echo $! > ${PIDFile}
        else 
            ${DockerCompose} up -d $2
        fi
        ;;
    stop)
        cd ${DockerDir}
        if [ -z "$2" ]; then
            ${DockerCompose} stop
            if [ -f ${PIDFile} ]; then
                rm ${PIDFile}
            fi
        else 
            ${DockerCompose} stop $2
        fi
        ;;
    restart)
        $0 stop $2
        sleep 1        
        $0 start $2
        ;;    
    status)
        cd ${DockerDir}
        if [ -z "$2" ]; then
            ${DockerCompose} ps
        else 
            ${DockerCompose} ps $2
        fi        
        ;;	
    *)
        echo "License Server Service ... "
        echo "Usage: $0 start|stop|restart|status"
        exit 1
        ;;
esac
