#!/bin/bash
#
# chroma-copytool-monitor Starts the chroma-copytool-monitor daemon
#
# chkconfig: 345 88 12
# description: Starts the chroma-copytool-monitor daemon
# processname: python

. /etc/init.d/functions

COPYTOOL_ID="{{ id }}"

SVC_NAME="Intel Manager For Lustre Copytool Monitor"
PID_FILE=/var/run/chroma-copytool-monitor-${COPYTOOL_ID}.pid
DAEMON_BIN=/usr/sbin/chroma-copytool-monitor

start() {
    status -p ${PID_FILE} ${SVC_NAME} > /dev/null

    if [ $? == 0 ]; then
        echo "Starting ${SVC_NAME} already running"
    else
        action "Starting ${SVC_NAME}: "
        ${DAEMON_BIN} ${COPYTOOL_ID} &
        PID=$!
        echo

        if [ -n ${PID} ]; then
            echo ${PID} > ${PID_FILE}
        fi
    fi
}

stop() {
    action "Stopping ${SVC_NAME}: " killproc -p ${PID_FILE}
    echo
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status -p ${PID_FILE} "${SVC_NAME}"
        exit $?
        ;;
    restart|force-reload)
        stop
        start
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0