-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteract.sh
executable file
·173 lines (139 loc) · 5.68 KB
/
interact.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
source /root/evernode_interactive/config.cfg
# Check atleast 3 arguments are given #
if [ $# -lt 2 ]
then
echo "Usage : $0 option pattern filename"
echo "Option: {list|restart|status_echo|status_reboot|status|config|push|ssh_key|server_reboot|apt_upgrade|release|offerlease} {all|host #}"
echo "config [resources|leaseamt|xahaud|xahaud-fallback|email|instance|extrafee] [arguments]"
exit
fi
#from terminal command
COMMAND=$1
ALL_OR_HOST=$2
#Resources
MEMORY=$5
SWAP=$6
DISK=$7
INSTANCES=$8
do_ssh() {
#from do_ssh args
local hostie=$1
case $COMMAND in
bash)
#List running instances on your nodes
#echo "Sending bash command to $hostie :$CONFIG_COMMANDS:"
echo "Issuing command: root@$hostie $CONFIG_COMMANDS $SET_CONFIG_COMMANDS"
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "$CONFIG_COMMANDS"
;;
restart)
#remotely restart server
echo "Restarting : $hostie";
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "shutdown -r now"
;;
status_echo)
#Display the evernode status 'active' or 'inactive' but take no action
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /root/scripts/check_status.sh"
;;
status_reboot)
#Reboot if evernode status is 'inactive'
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /root/scripts/check_status.sh reboot"
;;
status)
#Display the full 'evernode status' with QR code
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /usr/bin/evernode status"
;;
server_reboot)
#checks if /run/motd.dynamic has the message to restart the server in it
#TODO: check for other /run/<restart> files, varys from OS
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /root/scripts/check_status.sh server_reboot"
;;
apt_upgrade)
#apt update && apt upgrade
#note: sometimes cloud-init still requires manual intervention
echo "UPDATING!!!!!!!! : $hostie";
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "apt update -y && apt upgrade -y && reboot"
;;
list)
#List running instances on your nodes
echo "Instances running on node $hostie"
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /usr/bin/evernode list"
;;
config)
#Execute 'most' of the 'evernode config' commands remotely
if test $CONFIG_COMMANDS != "resources"; then
echo "Issuing command: root@$hostie bash -s < /usr/bin/evernode config $CONFIG_COMMANDS $SET_CONFIG_COMMANDS"
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /usr/bin/evernode config $CONFIG_COMMANDS $SET_CONFIG_COMMANDS"
else
#TODO: change resource allocation one reputation contracts have been rolled out and we have an idea of changes
echo "Resource re-allocation not configured YET"
echo "/usr/bin/evernode config resources <memory MB> <swap MB> <disk MB> <max instance count>"
echo "/usr/bin/evernode config $CONFIG_COMMANDS $MEMORY $SWAP $DISK $INSTANCES"
fi
;;
release)
#Execute 'most' of the 'evernode config' commands remotely
#echo "Issuing command: root@$hostie bash -s < /usr/bin/evernode config resources 0 0 0 3"
#ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /usr/bin/evernode config resources 0 0 0 3"
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /root/scripts/check_status.sh release"
;;
offerlease)
#Execute 'most' of the 'evernode config' commands remotely
echo "Issuing command: root@$hostie bash -s < /usr/bin/evernode offerlease"
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /usr/bin/evernode offerlease"
;;
push)
echo "connecting to: $hostie";
# StrictHostKeyChecking auto adds ssh fingerprint with out asking
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "rm -rf /root/scripts"
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "mkdir /root/scripts"
scp -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY ./scripts/*.sh root@$hostie:/root/scripts
;;
install_fail2ban)
#checks if /run/motd.dynamic has the message to restart the server in it
#TODO: check for other /run/<restart> files, varys from OS
#ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "bash -s < /root/scripts/install_fail2ban.sh"
ssh -o "StrictHostKeyChecking no" -i $SSH_PRIVATE_KEY root@$hostie "/root/scripts/install_fail2ban.sh"
;;
ssh_key)
echo "uploading public key to node $hostie"
ssh-copy-id -i $SSH_PUBLIC_KEY $hostie
esac
}
case $ALL_OR_HOST in
all)
CONFIG_COMMANDS=$3
if test -n $4; then
#echo "4th Argument is $4"
SET_CONFIG_COMMANDS=$4 #this is the argument to varible to change to
else
#echo "4th Argument is Empty!!"
SET_CONFIG_COMMANDS=""
fi
for ((i=1; i<$NUMBER_OF_NODES+1; i++))
do
if (( i < 10 )); then
#pad myhostname with "0" for first 9 hosts 01-09
MYHOST=$MYHOSTNAME"0"$i.$MYDOMAIN
else
#for nodes from 10 to 999 or more
MYHOST=$MYHOSTNAME$i.$MYDOMAIN
fi
#echo $MYHOST
do_ssh $MYHOST
done
;;
host)
CONFIG_COMMANDS=$4 # this is the config option
if test -n $5; then
#echo "5th Argument is $5"
SET_CONFIG_COMMANDS=$5 #this is the argument to varible to change to
else
#echo "5th Argument is Empty!!"
SET_CONFIG_COMMANDS=""
fi
#$3 is the HOSTS ID Number 01-20 from commandline ''./interact status host 01'
MYHOST=$MYHOSTNAME$3.$MYDOMAIN
do_ssh $MYHOST
;;
esac