#!/bin/bash

# prefcsd
#
# $Id: prefcsd 1757 2013-03-15 18:00:33Z jhealy $
#
# This is a FirstClass hook script.  It must reside in a folder that
# the FC init scripts (/etc/init.d/fc[i]sd) are configured to look for
# (/home/fcadmin/Documents by default, but Suffield Academy overrides this
# in the scripts to /opt/fcsd/suffield_prepost).
#
# This is a hook script that ties into commands issued by the
# FC Core Services controller, located at /usr/sbin/fcsctl.
# Please see that file for an idea of the types of commands that
# can be processed.
#
# Commands run in this script are run just BEFORE fcsctl starts
# the Core Services daemon on the machine.  Any arguments provided to
# fcsctl are passed directly to this script as well, one argument
# per invocation.  For example:
#
# /usr/sbin/fcsctl start status
#
# Would call this script with an arg of "start", then start the
# fcs service.  Next, it would call this script with an arg of
# "status", and then process the status argument itself.
#
# Finally, this script has access to any variable defined in the calling
# script.  Examples include:
#
#    SERVICE_NAME
#    SERVICE_APP
#    SERVICE_FOLDER
#    SERVICE_PID
#    USERDOCS
#

ARG="${1}"

echo "prefcsd: Executing preflight script with arg '${ARG}':"

case $ARG in
    start)
        # parent confirms that PID does not exist before calling preflight
	source "${USERDOCS}/fclogrotate"
	;;
    stop)
        # parent confirms that PID exists before calling preflight
	echo "prefcsd: No preflight operations for action '${ARG}'; skipping"
	;;
    restart)
        # parent confirms that PID exists before calling preflight
        # after this invocation, parent calls $0 start, so
        # you do not need to duplicate "start" options here
	echo "prefcsd: No preflight operations for action '${ARG}'; skipping"
	;;
    *)
	echo "prefcsd: Unknown argument '${ARG}'; skipping"
	;;
    
esac

