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/brmsgw"; then
112 component_status brmsgw
115 if check_x_file "${POLICY_HOME}/etc/init.d/paplp"; then
116 component_status paplp
119 if check_x_file "${POLICY_HOME}/etc/init.d/pdplp"; then
120 component_status pdplp
123 NUM_CRONS=$(crontab -l 2> /dev/null | wc -l)
124 echo " ${NUM_CRONS} cron jobs installed."
128 function policy_start() {
129 if [[ $DEBUG == y ]]; then
130 echo "-- ${FUNCNAME[0]} --"
134 if check_x_file "${POLICY_HOME}/etc/init.d/pap"; then
138 if check_x_file "${POLICY_HOME}/etc/init.d/pdp"; then
142 if check_x_file "${POLICY_HOME}/etc/init.d/configs"; then
143 component_start configs
146 if check_x_file "${POLICY_HOME}/etc/init.d/console"; then
147 component_start console
150 if check_x_file "${POLICY_HOME}/etc/init.d/brmsgw"; then
151 component_start brmsgw
154 if check_x_file "${POLICY_HOME}/etc/init.d/paplp"; then
155 component_start paplp
158 if check_x_file "${POLICY_HOME}/etc/init.d/pdplp"; then
159 component_start pdplp
162 cat "${POLICY_HOME}"/etc/cron.d/*.cron | crontab
165 function policy_stop() {
166 if [[ $DEBUG == y ]]; then
167 echo "-- ${FUNCNAME[0]} --"
171 pkill -f "/bin/bash ${POLICY_HOME}/bin/monitor.sh"
172 crontab -r > /dev/null 2>&1
175 if check_x_file "${POLICY_HOME}/etc/init.d/paplp"; then
179 if check_x_file "${POLICY_HOME}/etc/init.d/pdplp"; then
183 if check_x_file "${POLICY_HOME}/etc/init.d/brmsgw"; then
184 component_stop brmsgw
187 if check_x_file "${POLICY_HOME}/etc/init.d/console"; then
188 component_stop console
191 if check_x_file "${POLICY_HOME}/etc/init.d/configs"; then
192 component_stop configs
195 if check_x_file "${POLICY_HOME}/etc/init.d/pdp"; then
199 if check_x_file "${POLICY_HOME}/etc/init.d/pap"; then
205 #########################################################################
207 ## script execution body
209 #########################################################################
214 until [[ -z "$1" ]]; do
216 -d|--debug|debug) DEBUG=y
219 -i|--status|status) OPERATION=status
221 -s|--start|start) OPERATION=start
223 -h|--stop|stop|--halt|halt) OPERATION=halt
232 # operation validation
237 *) echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}";
243 if [[ -z ${POLICY_HOME} ]]; then
244 echo "error: POLICY_HOME is unset."
248 # operation validation
259 *) echo "invalid operation \(${OPERATION}\): must be in {status|start|stop}";