AyumuUeha | 76a01bc | 2017-05-18 13:34:13 +0900 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | #************************************************************/ |
| 3 | #** File: vsg_pppoe_cleanup.sh */ |
| 4 | #** Contents: Contains shell script to clean up all */ |
| 5 | #** artifacts tied to applications */ |
| 6 | #************************************************************/ |
| 7 | |
| 8 | source /tmp/vsg_env.txt |
| 9 | |
| 10 | date |
| 11 | echo "vsg_pppoe_cleanup.sh: Begin" |
| 12 | vsgIp=$1 |
| 13 | vcpeproxy_prefix=vcpe; export vcpeproxy_prefix |
| 14 | vcpe_gwbr_name=vcpe_gwbr; export vcpe_gwbr |
| 15 | vsg_home_dir=$2 |
| 16 | vcpe_monitor_script=vsg_vcpe_monitor.sh |
| 17 | container_volumes=/var/container_volumes |
| 18 | if [ $# -ne 2 ] |
| 19 | then |
| 20 | echo "Usage: vsg_pppoe_cleanup.sh <vsgIp> <vsg_home_dir>" |
| 21 | exit 0 |
| 22 | fi |
| 23 | |
| 24 | getArray() { |
| 25 | array=() # Create array |
| 26 | while IFS= read -r line # Read a line |
| 27 | do |
| 28 | array+=("$line") # Append line to the array |
| 29 | done < "$1" |
| 30 | } |
| 31 | |
| 32 | # |
| 33 | # Restarting a vcpeproxy will force the Docker instance to be cleaned up |
| 34 | # automatically. |
| 35 | # Note: Since vcpeproxy is created from XOS, if you want to delete that |
| 36 | # Docker instance, you will have to go through XOS make cleanup operation. |
| 37 | # |
| 38 | function restart_all_vcpeproxy() { |
| 39 | |
| 40 | echo "Restart all vcpeproxy..." |
| 41 | |
| 42 | file_temp="/tmp/vcpeproxy_names.txt" |
| 43 | |
| 44 | sudo docker ps|grep $vcpeproxy_prefix|awk '{print $NF}' > $file_temp |
| 45 | |
| 46 | getArray $file_temp |
| 47 | |
| 48 | for id in "${array[@]}" |
| 49 | do |
| 50 | echo "Restarting docker instance $id" |
| 51 | sudo docker exec $id sed -i "s/POST/DELETE/g" $NODEJS_MODULES_DIR$AP_REST_NETCFG |
| 52 | sudo docker exec $id bash $NODEJS_MODULES_DIR$AP_REST_NETCFG |
| 53 | sudo docker restart $id |
| 54 | done |
| 55 | } |
| 56 | |
| 57 | echo "Killall nodejs programs running in the VSG" |
| 58 | sudo killall nodejs |
| 59 | restart_all_vcpeproxy |
| 60 | if ifconfig -a |grep $vcpe_gwbr_name ; then |
| 61 | sudo ifconfig $vcpe_gwbr_name down |
| 62 | sudo brctl delbr $vcpe_gwbr_name |
| 63 | fi |
| 64 | if [ -d $vsg_home_dir ]; then |
| 65 | rm -rf $vsg_home_dir/* |
| 66 | fi |
| 67 | pid=`ps -fade|grep vsg_vcpe_monitor.sh|grep -v grep |awk '{print $2}'` |
| 68 | if echo $pid|grep [0-9] ; then |
| 69 | echo "Killing vsg_vcpe_monitor.sh script" |
| 70 | sudo kill -9 $pid |
| 71 | fi |
| 72 | date |
| 73 | echo "vsg_vcpegw_cleanup.sh: End" |