standup 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +8 -0
- data/Rakefile +24 -0
- data/VERSION +1 -0
- data/lib/standup/core_ext.rb +11 -0
- data/lib/standup/ec2/base.rb +61 -0
- data/lib/standup/ec2/elastic_ip.rb +49 -0
- data/lib/standup/ec2/instance.rb +80 -0
- data/lib/standup/ec2/security_group.rb +95 -0
- data/lib/standup/ec2/volume.rb +57 -0
- data/lib/standup/ec2.rb +5 -0
- data/lib/standup/node.rb +48 -0
- data/lib/standup/railtie.rb +10 -0
- data/lib/standup/remoting.rb +133 -0
- data/lib/standup/scripts/base.rb +52 -0
- data/lib/standup/settings.rb +16 -0
- data/lib/standup.rb +54 -0
- data/lib/tasks/standup.rake +19 -0
- data/scripts/allocate_ip.rb +7 -0
- data/scripts/basics.rb +6 -0
- data/scripts/ec2.rb +60 -0
- data/scripts/generate/script.rb +7 -0
- data/scripts/generate.rb +14 -0
- data/scripts/init/standup.yml +17 -0
- data/scripts/init.rb +7 -0
- data/scripts/localize.rb +18 -0
- data/scripts/passenger/nginx.conf +32 -0
- data/scripts/passenger/upstart.conf +10 -0
- data/scripts/passenger.rb +31 -0
- data/scripts/postgresql/postgresql.conf +501 -0
- data/scripts/postgresql.rb +24 -0
- data/scripts/ruby.rb +12 -0
- data/scripts/setup.rb +11 -0
- data/scripts/status.rb +15 -0
- data/scripts/terminate.rb +12 -0
- data/scripts/update.rb +15 -0
- data/scripts/webapp/nginx-server-fragment.conf +12 -0
- data/scripts/webapp.rb +79 -0
- data/standup.gemspec +95 -0
- metadata +198 -0
data/lib/standup.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'settingslogic'
|
2
|
+
require 'AWS'
|
3
|
+
require 'aws/s3'
|
4
|
+
require 'net/ssh'
|
5
|
+
require 'highline'
|
6
|
+
|
7
|
+
require 'standup/core_ext'
|
8
|
+
require 'standup/railtie'
|
9
|
+
require 'standup/settings'
|
10
|
+
require 'standup/ec2'
|
11
|
+
require 'standup/remoting'
|
12
|
+
require 'standup/scripts/base'
|
13
|
+
require 'standup/node'
|
14
|
+
|
15
|
+
module Standup
|
16
|
+
module Scripts; end
|
17
|
+
|
18
|
+
def self.nodes
|
19
|
+
Settings.nodes.keys.map{|name| Node.new name}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.gem_scripts_path
|
23
|
+
File.expand_path('../../scripts', __FILE__)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.local_scripts_path
|
27
|
+
File.expand_path('config/standup', Rails.root) rescue nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.scripts
|
31
|
+
unless class_variable_defined? :@@scripts
|
32
|
+
@@scripts = {}
|
33
|
+
loaded = Set.new
|
34
|
+
[local_scripts_path, gem_scripts_path].each do |dir|
|
35
|
+
Dir.foreach dir do |name|
|
36
|
+
next unless File.file? "#{dir}/#{name}"
|
37
|
+
next unless name =~ /\.rb$/
|
38
|
+
next if loaded.include? name
|
39
|
+
load "#{dir}/#{name}", true
|
40
|
+
loaded << name
|
41
|
+
end if dir && File.exists?(dir)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
@@scripts
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.script &block
|
48
|
+
name = block.__file__.match(/([^\/]*)\.rb$/)[1]
|
49
|
+
script_class = Class.new(Standup::Scripts::Base, &block)
|
50
|
+
script_class.name = name
|
51
|
+
Standup::Scripts.const_set name.camelize, script_class
|
52
|
+
scripts[name] = script_class
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
desc "List standup scripts"
|
2
|
+
task :standup do
|
3
|
+
puts
|
4
|
+
bright_p "Standup scripts list:"
|
5
|
+
offset = Standup.scripts.keys.map(&:length).max + 2
|
6
|
+
Standup.scripts.each do |name, script|
|
7
|
+
puts " rake standup:\e[1m#{"%-#{offset}s" % name}\e[0m #{script.description}"
|
8
|
+
end
|
9
|
+
puts
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :standup do
|
13
|
+
Standup.scripts.each do |name, _|
|
14
|
+
desc "Run script #{name} for each node"
|
15
|
+
task name.to_sym do
|
16
|
+
Standup.nodes.each {|node| node.run_script name}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/scripts/basics.rb
ADDED
data/scripts/ec2.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
Standup.script do
|
2
|
+
def run
|
3
|
+
ensure_security_group
|
4
|
+
|
5
|
+
open_port 22
|
6
|
+
|
7
|
+
ensure_instance
|
8
|
+
|
9
|
+
configure_elastic_ip
|
10
|
+
end
|
11
|
+
|
12
|
+
def open_ports *ports
|
13
|
+
ports.map(&:to_s).each do |port|
|
14
|
+
rule = Standup::EC2::SecurityGroup::IPRule.new('0.0.0.0/0', 'tcp', port, port)
|
15
|
+
group = Standup::EC2::SecurityGroup.list[node.id_group]
|
16
|
+
unless group.rules.include? rule
|
17
|
+
bright_p "opening port #{port}"
|
18
|
+
group.add_rule rule
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
alias :open_port :open_ports
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def ensure_security_group
|
27
|
+
return if Standup::EC2::SecurityGroup.list[node.id_group]
|
28
|
+
|
29
|
+
bright_p "creating security group #{node.id_group}"
|
30
|
+
Standup::EC2::SecurityGroup.create node.id_group
|
31
|
+
end
|
32
|
+
|
33
|
+
def ensure_instance
|
34
|
+
return if instance
|
35
|
+
|
36
|
+
bright_p "launching #{params.instance_type} instance with image #{params.image_id}"
|
37
|
+
inst = Standup::EC2::Instance.create params.image_id,
|
38
|
+
params.instance_type,
|
39
|
+
[Standup::EC2::SecurityGroup.list[node.id_group]]
|
40
|
+
puts "waiting until it's up"
|
41
|
+
inst.wait_until {inst.state != :running}
|
42
|
+
end
|
43
|
+
|
44
|
+
def configure_elastic_ip
|
45
|
+
if params.elastic_ip
|
46
|
+
unless params.elastic_ip == instance.external_ip
|
47
|
+
bright_p "attaching elastic ip #{params.elastic_ip}"
|
48
|
+
Standup::EC2::ElasticIP.list[params.elastic_ip].attach_to instance
|
49
|
+
|
50
|
+
puts "waiting until it's attached"
|
51
|
+
instance.wait_until {instance.external_ip != params.elastic_ip}
|
52
|
+
end
|
53
|
+
else
|
54
|
+
if ip = Standup::EC2::ElasticIP.list[instance.external_ip]
|
55
|
+
bright_p "detaching elastic ip #{params.elastic_ip}"
|
56
|
+
ip.detach
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/scripts/generate.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Standup.script do
|
2
|
+
self.description = 'Generate script'
|
3
|
+
|
4
|
+
def run
|
5
|
+
unless ENV['SCRIPT']
|
6
|
+
bright_p "Specify script name with SCRIPT=name argument"
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
10
|
+
FileUtils.mkdir_p(Standup.local_scripts_path)
|
11
|
+
FileUtils.copy script_file('script.rb'),
|
12
|
+
File.expand_path("#{ENV['SCRIPT']}.rb", Standup.local_scripts_path)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
aws:
|
2
|
+
account_id:
|
3
|
+
access_key_id:
|
4
|
+
secret_access_key:
|
5
|
+
keypair_name:
|
6
|
+
availability_zone: us-east-1a
|
7
|
+
|
8
|
+
nodes:
|
9
|
+
main:
|
10
|
+
ec2:
|
11
|
+
image_id: ami-480df921 # Canonical Ubuntu 10.04, EBS boot
|
12
|
+
instance_type: m1.small
|
13
|
+
ssh_user: ubuntu
|
14
|
+
# elastic_ip:
|
15
|
+
webapp:
|
16
|
+
github_user:
|
17
|
+
github_repo:
|
data/scripts/init.rb
ADDED
data/scripts/localize.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Standup.script do
|
2
|
+
self.description = 'Put specified script into project configuration'
|
3
|
+
|
4
|
+
def run
|
5
|
+
unless ENV['SCRIPT']
|
6
|
+
bright_p "Specify script name with SCRIPT=name argument"
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
10
|
+
FileUtils.mkdir_p(Standup.local_scripts_path)
|
11
|
+
[ENV['SCRIPT'], "#{ENV['SCRIPT']}.rb"].each do |path|
|
12
|
+
path = File.expand_path(path, Standup.gem_scripts_path)
|
13
|
+
if File.exists? path
|
14
|
+
FileUtils.cp_r path, Standup.local_scripts_path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#user nobody;
|
2
|
+
worker_processes 1;
|
3
|
+
|
4
|
+
events {
|
5
|
+
worker_connections 1024;
|
6
|
+
}
|
7
|
+
|
8
|
+
http {
|
9
|
+
passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.0;
|
10
|
+
passenger_ruby /usr/local/bin/ruby;
|
11
|
+
|
12
|
+
include mime.types;
|
13
|
+
default_type application/octet-stream;
|
14
|
+
|
15
|
+
sendfile on;
|
16
|
+
|
17
|
+
#keepalive_timeout 0;
|
18
|
+
keepalive_timeout 65;
|
19
|
+
|
20
|
+
gzip on;
|
21
|
+
gzip_buffers 16 8k;
|
22
|
+
gzip_disable "MSIE [1-6]\.";
|
23
|
+
gzip_proxied any;
|
24
|
+
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
|
25
|
+
|
26
|
+
client_max_body_size 100m;
|
27
|
+
|
28
|
+
passenger_max_pool_size 10;
|
29
|
+
|
30
|
+
# standup place server fragments here
|
31
|
+
# standup place server fragments here
|
32
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Standup.script do
|
2
|
+
def run
|
3
|
+
scripts.ec2.open_port 80
|
4
|
+
|
5
|
+
install_gem 'passenger', '3.0.0'
|
6
|
+
|
7
|
+
unless file_exists? '/opt/nginx/sbin/nginx'
|
8
|
+
install_package 'libcurl4-openssl-dev'
|
9
|
+
sudo 'passenger-install-nginx-module --auto --auto-download --prefix=/opt/nginx'
|
10
|
+
end
|
11
|
+
|
12
|
+
upload script_file('nginx.conf'),
|
13
|
+
:to =>'/opt/nginx/conf/nginx.conf',
|
14
|
+
:sudo => true
|
15
|
+
|
16
|
+
upload script_file('upstart.conf'),
|
17
|
+
:to =>'/etc/init/nginx.conf',
|
18
|
+
:sudo => true
|
19
|
+
sudo 'initctl reload-configuration'
|
20
|
+
|
21
|
+
restart_nginx
|
22
|
+
end
|
23
|
+
|
24
|
+
def restart_nginx
|
25
|
+
if exec('initctl status nginx') =~ /running/i
|
26
|
+
sudo 'initctl restart nginx'
|
27
|
+
else
|
28
|
+
sudo 'initctl start nginx'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|