openstudio-aws 0.5.0.rc8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openstudio/aws/aws.rb +9 -2
- data/lib/openstudio/aws/version.rb +1 -1
- data/lib/openstudio/lib/openstudio_aws_instance.rb +4 -0
- data/lib/openstudio/lib/openstudio_aws_wrapper.rb +32 -8
- data/lib/openstudio/lib/server_script.sh.docker.template +48 -0
- data/lib/openstudio/lib/worker_script.sh.docker.template +39 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13f49425895636ecaf4f257d16b89e4efa28804a
|
4
|
+
data.tar.gz: d7e29b456413dd3bb09b6c2608fcf8eea998a025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38fc83e9eb648bedd0abf099f1c6ca78e0b708424b4f1f3d033b08b70b0a9000590bda356ca56f73b649b26105a8beeb4eac07f0eb7f33bae324f266ade3b0a9
|
7
|
+
data.tar.gz: b5937079c74a4057e6b76b70255a0d0cea29aa2e92d9685c01d2f98c8361a3c1bc7db861640ad0fba10f24b0bcfe3ef0837c53c1e68946754674b3ba5966795a
|
data/lib/openstudio/aws/aws.rb
CHANGED
@@ -180,13 +180,18 @@ module OpenStudio
|
|
180
180
|
@os_aws.save_private_key @save_directory
|
181
181
|
end
|
182
182
|
|
183
|
+
user_data_file = @dockerized ? 'server_script.sh.docker.template' : 'server_script.sh.template'
|
184
|
+
|
183
185
|
server_options = {
|
184
186
|
user_id: options[:user_id],
|
185
187
|
tags: options[:tags],
|
186
188
|
subnet_id: options[:subnet_id],
|
187
|
-
associate_public_ip_address: options[:associate_public_ip_address]
|
189
|
+
associate_public_ip_address: options[:associate_public_ip_address],
|
190
|
+
user_data_file: user_data_file
|
188
191
|
}
|
189
192
|
|
193
|
+
server_options[:availability_zone] = options[:availability_zone] if options[:availability_zone]
|
194
|
+
|
190
195
|
# save the worker pem and public to the directory
|
191
196
|
# presently, this will always overwrite the worker key, is that okay? Is this really needed later?
|
192
197
|
@os_aws.save_worker_keys @save_directory
|
@@ -228,13 +233,15 @@ module OpenStudio
|
|
228
233
|
end
|
229
234
|
|
230
235
|
fail "Can't create workers without a server instance running" if @os_aws.server.nil?
|
236
|
+
user_data_file = @dockerized ? 'worker_script.sh.docker.template' : 'worker_script.sh.template'
|
231
237
|
|
232
238
|
unless number_of_instances == 0
|
233
239
|
worker_options = {
|
234
240
|
user_id: options[:user_id],
|
235
241
|
tags: options[:tags],
|
236
242
|
subnet_id: options[:subnet_id],
|
237
|
-
associate_public_ip_address: options[:associate_public_ip_address]
|
243
|
+
associate_public_ip_address: options[:associate_public_ip_address],
|
244
|
+
user_data_file: user_data_file
|
238
245
|
}
|
239
246
|
|
240
247
|
# if options[:ebs_volume_size]
|
@@ -383,12 +383,14 @@ class OpenStudioAwsWrapper
|
|
383
383
|
defaults = {
|
384
384
|
user_id: 'unknown_user',
|
385
385
|
tags: [],
|
386
|
-
ebs_volume_size: nil
|
386
|
+
ebs_volume_size: nil,
|
387
|
+
user_data_file: 'server_script.sh.template'
|
387
388
|
}
|
388
389
|
launch_options = defaults.merge(launch_options)
|
389
390
|
|
390
391
|
# replace the server_script.sh.template with the keys to add
|
391
|
-
|
392
|
+
|
393
|
+
user_data = File.read(File.join(File.expand_path(File.dirname(__FILE__)), launch_options[:user_data_file]))
|
392
394
|
user_data.gsub!(/SERVER_HOSTNAME/, 'openstudio.server')
|
393
395
|
user_data.gsub!(/WORKER_PRIVATE_KEY_TEMPLATE/, worker_keys.private_key.gsub("\n", '\\n'))
|
394
396
|
user_data.gsub!(/WORKER_PUBLIC_KEY_TEMPLATE/, worker_keys.ssh_public_key)
|
@@ -408,11 +410,12 @@ class OpenStudioAwsWrapper
|
|
408
410
|
user_id: 'unknown_user',
|
409
411
|
tags: [],
|
410
412
|
ebs_volume_size: nil,
|
411
|
-
availability_zone: @server.data.availability_zone
|
413
|
+
availability_zone: @server.data.availability_zone,
|
414
|
+
user_data_file: 'worker_script.sh.template'
|
412
415
|
}
|
413
416
|
launch_options = defaults.merge(launch_options)
|
414
417
|
|
415
|
-
user_data = File.read(File.expand_path(File.dirname(__FILE__))
|
418
|
+
user_data = File.read(File.join(File.expand_path(File.dirname(__FILE__)), launch_options[:user_data_file]))
|
416
419
|
user_data.gsub!(/SERVER_IP/, @server.data.private_ip_address)
|
417
420
|
user_data.gsub!(/SERVER_HOSTNAME/, 'openstudio.server')
|
418
421
|
user_data.gsub!(/WORKER_PUBLIC_KEY_TEMPLATE/, worker_keys.ssh_public_key)
|
@@ -474,25 +477,46 @@ class OpenStudioAwsWrapper
|
|
474
477
|
|
475
478
|
# blocking method that executes required commands for creating and provisioning a docker swarm cluster
|
476
479
|
def configure_swarm_cluster(save_directory)
|
480
|
+
logger.info('waiting for server user_data to complete')
|
481
|
+
@server.wait_command('while ! [ -e /home/ubuntu/user_data_done ]; do sleep 5; done && echo "true"')
|
477
482
|
logger.info('Running the configuration script for the server.')
|
478
|
-
@server.wait_command('
|
483
|
+
@server.wait_command('echo $(env) &> /home/ubuntu/env.log && echo "true"')
|
484
|
+
@server.wait_command('cp /home/ubuntu/server_provision.sh /home/ubuntu/server_provision.sh.bak && echo "true"')
|
485
|
+
@server.wait_command('sudo /home/ubuntu/server_provision.sh &> /home/ubuntu/server_provision.log && echo "true"')
|
479
486
|
logger.info('Downloading the swarm join command.')
|
480
487
|
swarm_file = File.join(save_directory, 'worker_swarm_join.sh')
|
481
488
|
@server.download_file('/home/ubuntu/swarmjoin.sh', swarm_file)
|
489
|
+
logger.info('waiting for worker user_data to complete')
|
490
|
+
@workers.each { |worker| worker.wait_command('while ! [ -e /home/ubuntu/user_data_done ]; do sleep 5; done && echo "true"') }
|
482
491
|
logger.info('Running the configuration script for the worker(s).')
|
483
|
-
@workers.each { |worker| worker.wait_command('sudo /home/ubuntu/worker_provision.sh && echo "true"') }
|
492
|
+
@workers.each { |worker| worker.wait_command('sudo /home/ubuntu/worker_provision.sh &> /home/ubuntu/worker_provision.log && echo "true"') }
|
484
493
|
logger.info('Successfully re-sized storage devices for all nodes. Joining server nodes to the swarm.')
|
485
494
|
worker_join_cmd = "#{File.read(swarm_file).strip} && echo \"true\""
|
486
495
|
@workers.each { |worker| worker.wait_command(worker_join_cmd) }
|
487
496
|
logger.info('All worker nodes have been added to the swarm. Setting environment variables and starting the cluster')
|
488
497
|
total_procs = @server.procs
|
489
498
|
@workers.each { |worker| total_procs += worker.procs }
|
490
|
-
|
499
|
+
max_requests = ((total_procs + 10) * 1.2).round
|
500
|
+
mongo_cores = (total_procs / 64.0).ceil
|
501
|
+
web_cores = (total_procs / 32.0).ceil
|
502
|
+
max_pool = 16 * web_cores
|
503
|
+
rez_mem = 512 * max_pool
|
504
|
+
total_procs = total_procs - mongo_cores - web_cores + 2
|
505
|
+
@server.shell_command("echo 'MAX_REQUESTS=#{max_requests}' >> /home/ubuntu/.env && echo \"true\"")
|
506
|
+
@server.shell_command("echo 'MONGO_CORES=#{mongo_cores}' >> /home/ubuntu/.env && echo \"true\"")
|
507
|
+
@server.shell_command("echo 'WEB_CORES=#{web_cores}' >> /home/ubuntu/.env && echo \"true\"")
|
508
|
+
@server.shell_command("echo 'MAX_POOL=#{max_pool}' >> /home/ubuntu/.env && echo \"true\"")
|
509
|
+
@server.shell_command("echo 'REZ_MEM=#{rez_mem}M' >> /home/ubuntu/.env && echo \"true\"")
|
510
|
+
@server.shell_command("echo 'OS_SERVER_NUMBER_OF_WORKERS=#{total_procs}' >> /home/ubuntu/.env && echo \"true\"")
|
511
|
+
@server.shell_command("echo '' >> /home/ubuntu/.env && echo \"true\"")
|
512
|
+
@server.shell_command("docker stack deploy --compose-file docker-compose.yml osserver && echo \"true\"")
|
491
513
|
sleep 10
|
492
514
|
logger.info('The OpenStudio Server stack has been started. Waiting for the server to become available.')
|
493
515
|
@server.wait_command("while ( nc -zv #{@server.ip} 80 3>&1 1>&2- 2>&3- ) | awk -F \":\" '$3 != \" Connection refused\" {exit 1}'; do sleep 5; done && echo \"true\"")
|
494
516
|
logger.info('The OpenStudio Server stack has become available. Scaling the worker nodes.')
|
495
|
-
@server.wait_command("docker service scale
|
517
|
+
@server.wait_command("docker service scale osserver_worker=#{total_procs} && echo \"true\"")
|
518
|
+
logger.info('Waiting up to two minutes for the osserver_worker service to scale.')
|
519
|
+
@server.wait_command("timeout 120 bash -c -- 'while [ $( docker service ls -f name=osserver_worker --format=\"{{.Replicas}}\" ) != \"#{total_procs}/#{total_procs}\" ]; do sleep 5; done'; echo \"true\"")
|
496
520
|
logger.info('The OpenStudio Server stack is booted and ready for analysis submissions.')
|
497
521
|
end
|
498
522
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# AWS Server Bootstrap File
|
4
|
+
# This script is used to configure the AWS boxes for OpenStudio-server
|
5
|
+
|
6
|
+
ENTRY="127.0.0.1 SERVER_HOSTNAME"
|
7
|
+
FILE=/etc/hosts
|
8
|
+
if grep -q "$ENTRY" $FILE; then
|
9
|
+
echo "Hosts '$SERVER_HOSTNAME' entry already exists"
|
10
|
+
else
|
11
|
+
sudo sh -c "echo $ENTRY >> /etc/hosts"
|
12
|
+
fi
|
13
|
+
|
14
|
+
WORKER_PRIVATE_KEY="WORKER_PRIVATE_KEY_TEMPLATE"
|
15
|
+
WORKER_PUBLIC_KEY="WORKER_PUBLIC_KEY_TEMPLATE"
|
16
|
+
|
17
|
+
USER=ubuntu
|
18
|
+
|
19
|
+
mkdir -p /home/$USER/.ssh && chmod 700 /home/$USER/.ssh
|
20
|
+
echo -e $WORKER_PRIVATE_KEY > /home/$USER/.ssh/id_rsa
|
21
|
+
echo -e $WORKER_PUBLIC_KEY > /home/$USER/.ssh/id_rsa.pub
|
22
|
+
chmod 600 /home/$USER/.ssh/id_rsa
|
23
|
+
chmod 644 /home/$USER/.ssh/id_rsa.pub
|
24
|
+
chown ubuntu.ubuntu /home/$USER/.ssh/id_rsa
|
25
|
+
chown ubuntu.ubuntu /home/$USER/.ssh/id_rsa.pub
|
26
|
+
|
27
|
+
# Only allow localhost (and localhosts IP) to connect ot itself with this key. The IP is used for R cluster
|
28
|
+
ENTRY="from=\"localhost,127.0.0.1\" $WORKER_PUBLIC_KEY"
|
29
|
+
FILE=/home/$USER/.ssh/authorized_keys
|
30
|
+
if grep -q "$ENTRY" $FILE; then
|
31
|
+
echo "Key already exists in file"
|
32
|
+
else
|
33
|
+
echo $ENTRY >> $FILE
|
34
|
+
fi
|
35
|
+
chmod 644 /home/$USER/.ssh/authorized_keys
|
36
|
+
|
37
|
+
# SSH config
|
38
|
+
echo -e "Host *\n\tStrictHostKeyChecking no" > /home/$USER/.ssh/config
|
39
|
+
chmod 644 /home/$USER/.ssh/config && chown ubuntu.ubuntu /home/$USER/.ssh/config
|
40
|
+
|
41
|
+
# ec2 instance information
|
42
|
+
curl -o /usr/local/bin/ec2-metadata http://s3.amazonaws.com/ec2metadata/ec2-metadata
|
43
|
+
chmod 775 /usr/local/bin/ec2-metadata
|
44
|
+
mkdir -p /etc/openstudio-server
|
45
|
+
ec2-metadata -a -i -t -h -o -z -p -v > /etc/openstudio-server/instance.yml
|
46
|
+
|
47
|
+
#file flag the user_data has completed
|
48
|
+
cat /dev/null > /home/ubuntu/user_data_done
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# AWS Worker Bootstrap File
|
4
|
+
# File used to configure worker nodes on AWS
|
5
|
+
|
6
|
+
# Change Host File Entries
|
7
|
+
ENTRY="SERVER_IP SERVER_HOSTNAME"
|
8
|
+
FILE=/etc/hosts
|
9
|
+
if grep -q "$ENTRY" $FILE; then
|
10
|
+
echo "entry already exists"
|
11
|
+
else
|
12
|
+
sh -c "echo $ENTRY >> $FILE"
|
13
|
+
fi
|
14
|
+
|
15
|
+
WORKER_PUBLIC_KEY="WORKER_PUBLIC_KEY_TEMPLATE"
|
16
|
+
|
17
|
+
# add the public key to authorized keys
|
18
|
+
USER=ubuntu
|
19
|
+
|
20
|
+
mkdir -p /home/$USER/.ssh && chmod 700 /home/$USER/.ssh
|
21
|
+
|
22
|
+
# Only access from the server node
|
23
|
+
ENTRY="from=\"SERVER_HOSTNAME\" $WORKER_PUBLIC_KEY"
|
24
|
+
FILE=/home/$USER/.ssh/authorized_keys
|
25
|
+
if grep -q "$ENTRY" $FILE; then
|
26
|
+
echo "Key already exists in file"
|
27
|
+
else
|
28
|
+
echo $ENTRY >> $FILE
|
29
|
+
fi
|
30
|
+
chmod 644 /home/$USER/.ssh/authorized_keys
|
31
|
+
|
32
|
+
# ec2 instance information
|
33
|
+
curl -o /usr/local/bin/ec2-metadata http://s3.amazonaws.com/ec2metadata/ec2-metadata
|
34
|
+
chmod 775 /usr/local/bin/ec2-metadata
|
35
|
+
mkdir -p /etc/openstudio-server
|
36
|
+
ec2-metadata -a -i -t -h -o -z -p -v > /etc/openstudio-server/instance.yml
|
37
|
+
|
38
|
+
#file flag the user_data has completed
|
39
|
+
cat /dev/null > /home/ubuntu/user_data_done
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openstudio-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.0
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Long
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-scp
|
@@ -123,7 +123,9 @@ files:
|
|
123
123
|
- lib/openstudio/lib/openstudio_aws_logger.rb
|
124
124
|
- lib/openstudio/lib/openstudio_aws_wrapper.rb
|
125
125
|
- lib/openstudio/lib/openstudio_cloud_watch.rb
|
126
|
+
- lib/openstudio/lib/server_script.sh.docker.template
|
126
127
|
- lib/openstudio/lib/server_script.sh.template
|
128
|
+
- lib/openstudio/lib/worker_script.sh.docker.template
|
127
129
|
- lib/openstudio/lib/worker_script.sh.template
|
128
130
|
- openstudio-aws.gemspec
|
129
131
|
- spec/aws_instances/aws_spec_api.rb
|