-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscylla-gce.sh
executable file
·181 lines (150 loc) · 5.04 KB
/
scylla-gce.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
174
175
176
177
178
179
180
181
#!/bin/bash
source ./config.sh
build_reloc_command() {
pushd ${SCYLLA_REPO}
./install-dependencies.sh
./reloc/build_reloc.sh
./reloc/build_rpm.sh
./reloc/python3/build_reloc.sh
./reloc/python3/build_rpm.sh
popd
pushd ${SCYLLA_TOOLS_JAVA_REPO}
./install-dependencies.sh
./reloc/build_reloc.sh
./reloc/build_rpm.sh
popd
pushd ${SCYLLA_JMX_REPO}
./install-dependencies.sh
./reloc/build_reloc.sh
./reloc/build_rpm.sh
popd
}
create_command() {
for node in $NODES
do
echo "Creating node ${node}..."
gcloud beta compute --project "${PROJECT}" instances create "${node}" \
--zone "${ZONE}" \
--machine-type "${MACHINE_TYPE}" \
--network "default" \
--maintenance-policy "MIGRATE" \
--service-account "skilled-adapter-452@appspot.gserviceaccount.com" \
--scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring.write","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" \
--min-cpu-platform "Automatic" \
--local-ssd interface="NVME" \
--local-ssd interface="NVME" \
--image "centos-7-v20190905" \
--image-project "centos-cloud" \
--boot-disk-size "200" \
--boot-disk-type "pd-standard" \
--boot-disk-device-name "${node}"
done
}
prepare_machine() {
local node=$1
shift 1
echo $node
(
cat <<END
#/bin/bash
sudo yum install -y tmux
sudo yum install -y ./rpms/*.rpm
sudo sed -i "s/#cluster_name: '.*Cluster'/cluster_name: '${CLUSTER_NAME}'/" /etc/scylla/scylla.yaml
sudo sed -i "s/seeds: \"127.0.0.1\"/seeds: \"${SEED_NODES}\"/" /etc/scylla/scylla.yaml
sudo sed -i "s/listen_address: localhost/listen_address: ${node}/" /etc/scylla/scylla.yaml
sudo sed -i "s/rpc_address: localhost/rpc_address: ${node}/" /etc/scylla/scylla.yaml
sudo scylla_setup --disks ${DISKS} --nic ${NIC} --setup-nic --no-enable-service --no-selinux-setup --no-bootparam-setup --no-cpuscaling-setup --no-fstrim-setup
cd /var/lib/scylla && sudo mkdir hints && sudo chown scylla:scylla ./hints
echo "Done"
END
) > prepare-${node}.sh
gcloud compute scp --zone=${ZONE} prepare-${node}.sh ${node}:~/prepare.sh
gcloud compute ssh --zone=${ZONE} ${node} --command="mkdir rpms"
gcloud compute scp --zone=${ZONE} ${SCYLLA_REPO}/build/redhat/RPMS/x86_64/*.rpm ${node}:~/rpms
gcloud compute scp --zone=${ZONE} ${SCYLLA_TOOLS_JAVA_REPO}/build/redhat/RPMS/noarch/*.rpm ${node}:~/rpms
gcloud compute scp --zone=${ZONE} ${SCYLLA_JMX_REPO}/build/redhat/RPMS/noarch/*.rpm ${node}:~/rpms
if [ -e ~/.tmux.conf ]
then
gcloud compute scp --zone=${ZONE} ~/.tmux.conf ${node}:~/
echo asd
fi
gcloud compute ssh --zone=${ZONE} ${node} --command="chmod u+x ./prepare.sh && ./prepare.sh ${node}"
rm -f prepare-${node}.sh
}
prepare_command() {
for node in $NODES
do
prepare_machine $node &> ${node}.log &
done
wait
}
upload_scylla() {
local node=$1
gcloud compute scp --zone=${ZONE} ${SCYLLA_REPO}/build/release/scylla ${node}:~/
gcloud compute ssh --zone=${ZONE} ${node} --command="/opt/scylladb/bin/patchelf --set-interpreter /opt/scylladb/libreloc/ld.so ~/scylla"
gcloud compute ssh --zone=${ZONE} ${node} --command="sudo systemctl stop scylla-server"
gcloud compute ssh --zone=${ZONE} ${node} --command="sudo cp -v ~/scylla /opt/scylladb/libexec/scylla"
gcloud compute ssh --zone=${ZONE} ${node} --command="sudo systemctl start scylla-server"
}
upload_command() {
for node in $NODES
do
upload_scylla ${node} &> ${node}.log &
done
wait
}
foreach_command() {
args="${@}"
for node in $NODES
do
gcloud compute ssh --zone=${ZONE} ${node} --command="${args}" &> ${node}.log &
done
wait
}
usage() {
echo "Usage: $0 {command}"
echo "Commands:"
echo " build_reloc - build relocatable packages in all repositories (scylla.git, scylla-tools-java.git, scylla-jmx.git)"
echo " create - create the GCE machines"
echo " prepare - prepare the GCE machines, install and configure scylla"
echo " upload - upload a new scylla executable"
echo " foreach - execute a command on each machine"
}
if [ $# -lt 1 ]
then
echo "Missing mandatory command argument."
usage
exit 1
fi
case $1 in
build_reloc)
cmd=build_reloc_command
;;
create)
cmd=create_command
;;
prepare)
cmd=prepare_command
;;
upload)
cmd=upload_command
;;
foreach)
cmd=foreach_command
;;
--help)
usage
exit 0
;;
-h)
usage
exit 0
;;
*)
echo "Invalid command '${1}', valid commands are: build_reloc, create, prepare and foreach"
usage
exit 1
;;
esac
shift 1
${cmd} $@