2 # ============LICENSE_START=======================================================
4 # ================================================================================
5 # Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 # ================================================================================
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 # ============LICENSE_END=========================================================
24 echo -n "syntax: $(basename $0) "
29 echo "$(date +"%Y-%m-%d_%H-%M-%S") $1" >> ${POLICY_HOME}/logs/monitor.log
33 if [[ $DEBUG == y ]]; then
34 echo "-- ${FUNCNAME[0]} --"
41 if [[ -z ${COMPONENT} ]]; then
42 log "WARNING: invalid invocation: no component provided"
46 if [[ -z ${STATUS} ]]; then
47 log "WARNING: invalid invocation: no on/off/uninstalled switch provided for ${COMPONENT}"
51 if [[ "${STATUS}" == "off" ]]; then
54 if [[ "${STATUS}" == "on" ]]; then
61 if [[ $DEBUG == y ]]; then
62 echo "-- ${FUNCNAME[0]} --"
68 ${POLICY_HOME}/etc/init.d/${COMPONENT} status
69 if [[ $? != 0 ]]; then
70 log "starting ${COMPONENT}"
72 ${POLICY_HOME}/etc/init.d/${COMPONENT} umstart
74 log "OK: ${COMPONENT} (UP)"
79 if [[ $DEBUG == y ]]; then
80 echo "-- ${FUNCNAME[0]} --"
86 ${POLICY_HOME}/etc/init.d/${COMPONENT} status
87 if [[ $? != 0 ]]; then
88 log "OK: ${COMPONENT} (DOWN)"
91 log "stopping ${COMPONENT}"
92 ${POLICY_HOME}/etc/init.d/${COMPONENT} umstop
97 if [[ $DEBUG == y ]]; then
98 echo "-- ${FUNCNAME[0]} --"
102 CONF_FILE=${POLICY_HOME}/etc/monitor/monitor.cfg
103 while read line || [ -n "${line}" ]; do
104 if [[ -n ${line} ]] && [[ ${line} != *#* ]]; then
105 component=$(echo "${line}" | awk -F = '{print $1;}')
106 status=$(echo "${line}" | awk -F = '{print $2;}')
107 if [[ -n ${component} ]] && [[ -n ${status} ]]; then
108 monitor ${component} ${status}
111 done < "${CONF_FILE}"
118 until [[ -z "$1" ]]; do
120 -d|--debug|debug) DEBUG=y
130 if pidof -o %PPID -x $(basename $0) > /dev/null 2>&1; then
131 log "WARNING: $(basename $0) from the previous iteration still running. Exiting."
135 . ${POLICY_HOME}/etc/profile.d/env.sh