#!/bin/sh

# Helper script to start and stop DAQ node services

MYDIR=`dirname $0` && cd $MYDIR && MYDIR=`pwd`

# The list below defines order of starting/stopping services
startList="mongodb mongo-express daq-web-service cat-web-service"
stopList="cat-web-service daq-web-service mongo-express mongodb"
restartList=$startList
statusList=$startList

# Check action
action=$1
case $action in
    start|stop|restart|status)
    ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 1
esac

# Perform action
cd $MYDIR
serviceList="\$"${action}List
serviceList=`eval "echo $serviceList"`
for service in $serviceList; do
    dm-$service $action 
    sleep 1
done