Matteo Scandolo | aca8665 | 2017-08-08 13:05:27 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
AyumuUeha | 76a01bc | 2017-05-18 13:34:13 +0900 | [diff] [blame] | 17 | #!/bin/bash |
| 18 | #************************************************************/ |
| 19 | #** File: vsg_pppoe_cleanup.sh */ |
| 20 | #** Contents: Contains shell script to clean up all */ |
| 21 | #** artifacts tied to applications */ |
| 22 | #************************************************************/ |
| 23 | |
| 24 | source /tmp/vsg_env.txt |
| 25 | |
| 26 | date |
| 27 | echo "vsg_pppoe_cleanup.sh: Begin" |
| 28 | vsgIp=$1 |
| 29 | vcpeproxy_prefix=vcpe; export vcpeproxy_prefix |
| 30 | vcpe_gwbr_name=vcpe_gwbr; export vcpe_gwbr |
| 31 | vsg_home_dir=$2 |
| 32 | vcpe_monitor_script=vsg_vcpe_monitor.sh |
| 33 | container_volumes=/var/container_volumes |
| 34 | if [ $# -ne 2 ] |
| 35 | then |
| 36 | echo "Usage: vsg_pppoe_cleanup.sh <vsgIp> <vsg_home_dir>" |
| 37 | exit 0 |
| 38 | fi |
| 39 | |
| 40 | getArray() { |
| 41 | array=() # Create array |
| 42 | while IFS= read -r line # Read a line |
| 43 | do |
| 44 | array+=("$line") # Append line to the array |
| 45 | done < "$1" |
| 46 | } |
| 47 | |
| 48 | # |
| 49 | # Restarting a vcpeproxy will force the Docker instance to be cleaned up |
| 50 | # automatically. |
| 51 | # Note: Since vcpeproxy is created from XOS, if you want to delete that |
| 52 | # Docker instance, you will have to go through XOS make cleanup operation. |
| 53 | # |
| 54 | function restart_all_vcpeproxy() { |
| 55 | |
| 56 | echo "Restart all vcpeproxy..." |
| 57 | |
| 58 | file_temp="/tmp/vcpeproxy_names.txt" |
| 59 | |
| 60 | sudo docker ps|grep $vcpeproxy_prefix|awk '{print $NF}' > $file_temp |
| 61 | |
| 62 | getArray $file_temp |
| 63 | |
| 64 | for id in "${array[@]}" |
| 65 | do |
| 66 | echo "Restarting docker instance $id" |
| 67 | sudo docker exec $id sed -i "s/POST/DELETE/g" $NODEJS_MODULES_DIR$AP_REST_NETCFG |
| 68 | sudo docker exec $id bash $NODEJS_MODULES_DIR$AP_REST_NETCFG |
| 69 | sudo docker restart $id |
| 70 | done |
| 71 | } |
| 72 | |
| 73 | echo "Killall nodejs programs running in the VSG" |
| 74 | sudo killall nodejs |
| 75 | restart_all_vcpeproxy |
| 76 | if ifconfig -a |grep $vcpe_gwbr_name ; then |
| 77 | sudo ifconfig $vcpe_gwbr_name down |
| 78 | sudo brctl delbr $vcpe_gwbr_name |
| 79 | fi |
| 80 | if [ -d $vsg_home_dir ]; then |
| 81 | rm -rf $vsg_home_dir/* |
| 82 | fi |
| 83 | pid=`ps -fade|grep vsg_vcpe_monitor.sh|grep -v grep |awk '{print $2}'` |
| 84 | if echo $pid|grep [0-9] ; then |
| 85 | echo "Killing vsg_vcpe_monitor.sh script" |
| 86 | sudo kill -9 $pid |
| 87 | fi |
| 88 | date |
| 89 | echo "vsg_vcpegw_cleanup.sh: End" |