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) "
26 echo "status|start|stop"
29 function check_r_file() {
30 if [[ $DEBUG == y ]]; then
31 echo "-- ${FUNCNAME[0]} --"
36 if [[ ! -f ${FILE} || ! -r ${FILE} ]]; then
43 function check_x_file() {
44 if [[ $DEBUG == y ]]; then
45 echo "-- ${FUNCNAME[0]} --"
50 if [[ ! -f ${FILE} || ! -x ${FILE} ]]; then
57 function component_status() {
59 output=$("${POLICY_HOME}"/etc/init.d/"${COMPONENT}" status)
60 if [[ $? == 0 ]]; then
61 echo " ${COMPONENT}: UP: ${output}"
63 echo " ${COMPONENT}: DOWN"
67 function component_start() {
69 "${POLICY_HOME}"/etc/init.d/"${COMPONENT}" status > /dev/null 2>&1
70 if [[ $? == 0 ]]; then
71 echo " ${COMPONENT}: UP: already running .."
73 "${POLICY_HOME}"/etc/init.d/"${COMPONENT}" start > /dev/null 2>&1
74 echo " ${COMPONENT}: STARTING .."
78 function component_stop() {
80 "${POLICY_HOME}"/etc/init.d/"${COMPONENT}" status > /dev/null 2>&1
81 if [[ $? != 0 ]]; then
82 echo " ${COMPONENT}: DOWN: already stopped .."
84 "${POLICY_HOME}"/etc/init.d/"${COMPONENT}" stop > /dev/null 2>&1
85 echo " ${COMPONENT}: STOPPING .."
89 function policy_status() {
90 if [[ $DEBUG == y ]]; then
91 echo "-- ${FUNCNAME[0]} --"
95 if check_x_file "${POLICY_HOME}/etc/init.d/pap"; then
99 if check_x_file "${POLICY_HOME}/etc/init.d/pdp"; then
103 if check_x_file "${POLICY_HOME}/etc/init.d/configs"; then
104 component_status configs
107 if check_x_file "${POLICY_HOME}/etc/init.d/console"; then
108 component_status console
111 if check_x_file "${POLICY_HOME}/etc/init.d/elk"; then
115 if check_x_file "${POLICY_HOME}/etc/init.d/brmsgw"; then
116 component_status brmsgw
119 if check_x_file "${POLICY_HOME}/etc/init.d/paplp"; then
120 component_status paplp
123 if check_x_file "${POLICY_HOME}/etc/init.d/pdplp"; then
124 component_status pdplp
127 NUM_CRONS=$(crontab -l 2> /dev/null | wc -l)
128 echo " ${NUM_CRONS} cron jobs installed."
132 function policy_start() {
133 if [[ $DEBUG == y ]]; then
134 echo "-- ${FUNCNAME[0]} --"
138 if check_x_file "${POLICY_HOME}/etc/init.d/pap"; then
142 if check_x_file "${POLICY_HOME}/etc/init.d/pdp"; then
146 if check_x_file "${POLICY_HOME}/etc/init.d/configs"; then
147 component_start configs
150 if check_x_file "${POLICY_HOME}/etc/init.d/console"; then
151 component_start console
154 if check_x_file "${POLICY_HOME}/etc/init.d/elk"; then
158 if check_x_file "${POLICY_HOME}/etc/init.d/brmsgw"; then
159 component_start brmsgw
162 if check_x_file "${POLICY_HOME}/etc/init.d/paplp"; then
163 component_start paplp
166 if check_x_file "${POLICY_HOME}/etc/init.d/pdplp"; then
167 component_start pdplp
170 cat "${POLICY_HOME}"/etc/cron.d/*.cron | crontab
173 function policy_stop() {
174 if [[ $DEBUG == y ]]; then
175 echo "-- ${FUNCNAME[0]} --"
179 pkill -f "/bin/bash ${POLICY_HOME}/bin/monitor.sh"
180 crontab -r > /dev/null 2>&1
183 if check_x_file "${POLICY_HOME}/etc/init.d/paplp"; then
187 if check_x_file "${POLICY_HOME}/etc/init.d/pdplp"; then
191 if check_x_file "${POLICY_HOME}/etc/init.d/brmsgw"; then
192 component_stop brmsgw
195 if check_x_file "${POLICY_HOME}/etc/init.d/console"; then
196 component_stop console
199 if check_x_file "${POLICY_HOME}/etc/init.d/elk"; then
203 if check_x_file "${POLICY_HOME}/etc/init.d/configs"; then
204 component_stop configs
207 if check_x_file "${POLICY_HOME}/etc/init.d/pdp"; then
211 if check_x_file "${POLICY_HOME}/etc/init.d/pap"; then
217 #########################################################################
219 ## script execution body
221 #########################################################################
226 until [[ -z "$1" ]]; do
228 -d|--debug|debug) DEBUG=y
231 -i|--status|status) OPERATION=status
233 -s|--start|start) OPERATION=start
235 -h|--stop|stop|--halt|halt) OPERATION=halt
244 # operation validation
249 *) echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}";
255 if [[ -z ${POLICY_HOME} ]]; then
256 echo "error: POLICY_HOME is unset."
260 # operation validation
271 *) echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}";