~fkooman/vpn-maint-scripts

ref: c4291d418191c4ac07d3f90a3fe9f354c28ea6d3 vpn-maint-scripts/bin/vpn-maint-update-system-multi -rwxr-xr-x 2.3 KiB
c4291d41François Kooman remove some old CentOS stuff 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh

SERVER_LIST_FILE=server.list
REBOOT_TIME_CONTROLLER=120

if [ ! -f "${SERVER_LIST_FILE}" ]; then
    echo "\"${SERVER_LIST_FILE}\" not found!"
    exit 1
fi

# import the "server.list" file
. ./${SERVER_LIST_FILE}

if [ -z "${CONTROLLERS}" ]; then
    echo "\"CONTROLLERS\" not set in \"${SERVER_LIST_FILE}\""
    exit 1
fi

if [ -z "${NODES}" ]; then
    echo "\"NODES\" not set in \"${SERVER_LIST_FILE}\""
    exit 1
fi

echo "**********************************************************"
echo "*                                                        *"
echo "*   Are you sure you want to UPDATE your VPN servers?    *"
echo "*                                                        *"
echo "*         All VPN clients will be disconnected!          *"
echo "*                                                        *"
echo "**********************************************************"
echo
echo "CONTROLLER(S): "
for CONTROLLER in ${CONTROLLERS}; do
    echo "* ${CONTROLLER}"
done
echo "NODE(S): "
for NODE in ${NODES}; do
    echo "* ${NODE}"
done
echo
printf "Continue? (y/n) [n]: "; read -r CONFIRM
if ! [ "${CONFIRM}" = "y" ] && ! [ "${CONFIRM}" = "Y" ]; then
    exit 1
fi

# stop all nodes
for NODE in ${NODES}
do
    echo "Stopping NODE ${NODE}..."
    ssh -t "${NODE}" "/usr/bin/tmux new '/usr/bin/sudo /usr/sbin/vpn-maint-stop-node'"
done

# update controllers
for CONTROLLER in ${CONTROLLERS}
do
    echo "Updating CONTROLLER ${CONTROLLER}..."

    ssh -t "${CONTROLLER}" "/usr/bin/tmux new '/usr/bin/sudo /usr/sbin/vpn-maint-update-controller -y'"
    if [ "--reboot" = "${1}" ]; then
        echo "Rebooting CONTROLLER ${CONTROLLER}..."
        ssh "${CONTROLLER}" "/usr/bin/sudo /sbin/reboot"
    fi
done

if [ "--reboot" = "${1}" ]; then
    echo "Waiting ${REBOOT_TIME_CONTROLLER}s for CONTROLLERS to come back..."
    sleep ${REBOOT_TIME_CONTROLLER}
fi

# update nodes
for NODE in ${NODES}
do
    echo "Updating NODE ${NODE}..."
    ssh -t "${NODE}" "/usr/bin/tmux new '/usr/bin/sudo /usr/sbin/vpn-maint-update-node'"
    if [ "--reboot" = "${1}" ]; then
        echo "Rebooting NODE ${NODE}..."
        ssh "${NODE}" "/usr/bin/sudo /sbin/reboot"
    else
        echo "Starting NODE ${NODE}..."
        ssh -t "${NODE}" "/usr/bin/tmux new '/usr/bin/sudo /usr/sbin/vpn-maint-start-node'"
    fi
done