-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEXPERIMENTAL_Plugin_parallel_update_script.sh
110 lines (89 loc) · 3.28 KB
/
EXPERIMENTAL_Plugin_parallel_update_script.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
# Set filename to obtain IP address list for Plugin Node VPS's to Update
BASEFILE="user_at_ip"
# The plain ipaddresses file will be autogenerated from our BASEFILE further down
IPFILE="ip_addresses"
# Set Colour Vars
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo
echo
echo -e "${RED} #################################################### ${NC}"
echo -e "${RED} # # ${NC}"
echo -e "${RED} # WARNING EXPERIMENTAL SCRIPT FOR # ${NC}"
echo -e "${RED} # PARALLEL OS UPDATE OF # ${NC}"
echo -e "${RED} # MULTIPLE PLUGIN NODES # ${NC}"
echo -e "${RED} # # ${NC}"
echo -e "${RED} # Created by s4njk4n - https://github.com/s4njk4n/ # ${NC}"
echo -e "${RED} # # ${NC}"
echo -e "${RED} #################################################### ${NC}"
echo
echo
# Set time (in seconds) to wait for your VPS to reboot. You'll have to manually test this. Recommend rounding UP by a minute or 2
echo
echo -e "${RED}How long (in seconds) should be allowed for VPS's to reboot?${NC}"
echo
echo -e "${RED}NOTE: If your VPS's take variable amounts of time to update and reboot${NC}"
echo -e "${RED}then the time you want to specify here is the total number of seconds to${NC}"
echo -e "${RED}wait for all updates and a reboot to complete on your SLOWEST VPS. You may${NC}"
echo -e "${RED}need to work it out by trial and error. Selecting a time too short is not${NC}"
echo -e "${RED}harmful. The final status checks may just not display a useful output.${NC}"
echo -e "${RED}If unsure, set it to something long like 600(seconds). Setting a longer${NC}"
echo -e "${RED}time isn't harmful, it will just take longer to finish the update.${NC}"
read WAITTOREBOOT
echo
echo
echo -e "${GREEN}Generating plain IP address list ${NC}"
rm $IPFILE > /dev/null 2>&1
cut -d "@" -f 2 $BASEFILE > $IPFILE
echo
echo
# Create a temporary script for remote execution
REMOTE_SCRIPT=$(mktemp)
# Define the commands to be executed remotely
cat <<EOF > $REMOTE_SCRIPT
#!/bin/bash
sudo -n apt-get update -y
sudo -n apt-get upgrade -y
sudo -n apt-get autoremove -y
sudo -n apt-get clean -y
sudo -n apt-get update -y
sudo -n apt-get upgrade -y
sudo -n apt-get autoremove -y
sudo -n apt-get clean -y
sudo -n reboot
EOF
# Set up pssh options
PSSH_OPTIONS="-h $IPFILE -l root -t 0"
echo
echo -e "${GREEN}Updating Plugin Nodes OS${NC}"
echo
# Execute the remote commands in parallel using pssh
parallel-ssh $PSSH_OPTIONS -i -I < $REMOTE_SCRIPT
echo
echo -e "${GREEN}Rebooting Plugin Nodes${NC}"
echo
# Wait for the specified time for the nodes to reboot
sleep $WAITTOREBOOT
echo
echo
echo -e "${GREEN}Retrieving Status of Plugin Nodes${NC}"
echo
echo
# Retrieve the status of Plugin Nodes using SSH connections
while IFS="@" read -r f1 f2
do
echo -e "${GREEN}Retrieving Status of Plugin Node - $f2 ${NC}"
echo
ssh -n $f1@$f2 'pm2 status'
echo
echo
echo -e "${GREEN}--------------------------------------------------------------- ${NC}"
echo
done < $BASEFILE
rm $REMOTE_SCRIPT
rm $IPFILE
echo -e "${RED}ALL PLUGIN NODE OS UPDATES COMPLETED ${NC}"
echo