#!/bin/bash
#!-*- sh -*-
#
# Copyright: See the COPYRIGHT that is included with this distribution.
#            EPICS exampleCPP is distributed subject to a Software License
#            Agreement found in file LICENSE that is included with this
#            distribution.
#
# Abs: start_server starts the channel archiver service, which can query a
#      Channel Archiver index files, with a given service name 
#
# Rem: The Channel Archiver Service is an example of an EPICS v4 RPC service.
# 
#
# Usage: start_server -h
#        start_server [-S service_name] [index_1 ... index_n]                   
# 
# ----------------------------------------------------------------------------
# Auth: Dave Hickin (david.hickin@diamond.ac.uk)
# ============================================================================

TOP=$(dirname $0)
DEFAULT_SERVICE="archiveService"
DEFAULT_INDEX="$TOP/data/fredjanet/index"
SERVICE=${DEFAULT_SERVICE}

Error()
{
    echo "Error: $@" >&2;
    usage
    exit 1;
}

usage()
{
cat << EOF
Usage:
     start_server [-S service_name] [index_1 ... index_n]    
EOF
}

while getopts :hS: OPTION
do
    case $OPTION in
    h) usage
       exit
       ;;

    S) SERVICE="$OPTARG"
       ;;

    ?) Error invalid option or missing argument
       ;;
    esac
done
shift $((OPTIND-1))

if [ $# -eq 0 ]; then
     $TOP/bin/$EPICS_HOST_ARCH/ArchiverServiceRPC ${SERVICE} ${DEFAULT_INDEX} 
else
     $TOP/bin/$EPICS_HOST_ARCH/ArchiverServiceRPC ${SERVICE} "$@"
fi


