alex_sh | 9d980ce | 2017-08-23 17:30:56 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Alex Shatov | a5bfd6a | 2017-09-15 14:03:13 -0400 | [diff] [blame] | 3 | # ============LICENSE_START======================================================= |
Lusheng Ji | 967cc9a | 2018-02-12 10:45:42 -0500 | [diff] [blame] | 4 | # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. |
alex_sh | 9d980ce | 2017-08-23 17:30:56 -0400 | [diff] [blame] | 5 | # ================================================================================ |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # ============LICENSE_END========================================================= |
| 18 | # |
| 19 | # ECOMP is a trademark and service mark of AT&T Intellectual Property. |
| 20 | |
| 21 | mkdir -p logs |
| 22 | LOG_FILE=logs/policy_handler.log |
Alex Shatov | d444b32 | 2018-06-21 09:19:07 -0400 | [diff] [blame^] | 23 | exec &>> >(tee -a ${LOG_FILE}) |
| 24 | echo "---------------------------------------------" |
| 25 | STARTED=$(date +%Y-%m-%d_%T.%N) |
| 26 | echo "${STARTED}: running ${BASH_SOURCE[0]}" |
| 27 | echo "APP_VER =" $(python setup.py --version) |
| 28 | (uname -a; echo "/etc/hosts"; cat /etc/hosts; pwd) |
Alex Shatov | c9ec231 | 2018-06-14 12:06:42 -0400 | [diff] [blame] | 29 | |
Alex Shatov | d444b32 | 2018-06-21 09:19:07 -0400 | [diff] [blame^] | 30 | python -m policyhandler & |
alex_sh | 9d980ce | 2017-08-23 17:30:56 -0400 | [diff] [blame] | 31 | PID=$! |
| 32 | |
alex_sh | 9d980ce | 2017-08-23 17:30:56 -0400 | [diff] [blame] | 33 | function finish { |
Alex Shatov | d444b32 | 2018-06-21 09:19:07 -0400 | [diff] [blame^] | 34 | echo "killing policy_handler ${PID}" $(date +%Y_%m%d-%T.%N) |
alex_sh | 9d980ce | 2017-08-23 17:30:56 -0400 | [diff] [blame] | 35 | kill -9 ${PID} |
Alex Shatov | d444b32 | 2018-06-21 09:19:07 -0400 | [diff] [blame^] | 36 | echo "killed policy_handler ${PID}" $(date +%Y_%m%d-%T.%N) |
alex_sh | 9d980ce | 2017-08-23 17:30:56 -0400 | [diff] [blame] | 37 | } |
| 38 | trap finish SIGHUP SIGINT SIGTERM |
| 39 | |
Alex Shatov | d444b32 | 2018-06-21 09:19:07 -0400 | [diff] [blame^] | 40 | echo "running policy_handler as ${PID} logs to ${LOG_FILE}" |
| 41 | (free -h; df -h; ps afxvw; ss -aepi) |
Alex Shatov | 5105258 | 2018-05-18 15:13:40 -0400 | [diff] [blame] | 42 | |
alex_sh | 9d980ce | 2017-08-23 17:30:56 -0400 | [diff] [blame] | 43 | wait ${PID} |
Alex Shatov | d444b32 | 2018-06-21 09:19:07 -0400 | [diff] [blame^] | 44 | exec &>> >(tee -a ${LOG_FILE}) |
| 45 | echo "---------------------------------------------" |
| 46 | echo "$(date +%Y-%m-%d_%T.%N): exit ${BASH_SOURCE[0]} that was started on ${STARTED}" |
| 47 | |
alex_sh | 9d980ce | 2017-08-23 17:30:56 -0400 | [diff] [blame] | 48 | mv ${LOG_FILE} ${LOG_FILE}.$(date +%Y-%m-%d_%H%M%S) |