Module: Standup

Defined in:
lib/standup.rb,
lib/standup/node.rb,
lib/standup/version.rb,
lib/standup/ec2/base.rb,
lib/standup/remoting.rb,
lib/standup/settings.rb,
lib/standup/settings.rb,
lib/standup/ec2/volume.rb,
lib/standup/ec2/instance.rb,
lib/standup/scripts/base.rb,
lib/standup/scripts/node.rb,
lib/standup/ec2/elastic_ip.rb,
lib/standup/ec2/security_group.rb

Defined Under Namespace

Modules: EC2, Scripts Classes: Node, Remoting, Settings

Constant Summary collapse

VERSION =
'0.6.9'

Class Method Summary collapse

Class Method Details

.conf_scripts_pathObject



33
34
35
# File 'lib/standup.rb', line 33

def self.conf_scripts_path
  File.expand_path("#{Settings.conf_scripts_path}/config/standup") rescue nil
end

.gem_scripts_pathObject



25
26
27
# File 'lib/standup.rb', line 25

def self.gem_scripts_path
  File.expand_path('../../scripts',  __FILE__)
end

.local_scripts_pathObject



29
30
31
# File 'lib/standup.rb', line 29

def self.local_scripts_path
  File.expand_path('config/standup') rescue nil
end

.nodesObject



21
22
23
# File 'lib/standup.rb', line 21

def self.nodes
  Settings.nodes.keys.map{|name| Node.new name}
end

.run_from_command_lineObject



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
# File 'lib/standup.rb', line 68

def self.run_from_command_line
  if File.exists?('Gemfile') && !ENV['BUNDLE_GEMFILE']
    Kernel.exec "bundle exec standup #{ARGV.join(' ')}"
  end
  
  opt_parser = Trollop::Parser.new do
    version "Standup #{Standup.version} (c) 2010 Ilia Ablamonov, Artem Orlov, Cloud Castle Inc."

    banner 'Standup is an application deployment and infrastructure management tool for Rails and Amazon EC2.'
    banner ''
    banner 'Usage:'
    banner '       standup [options] <script> [script arguments]'
    banner ''
    banner 'where <script> is one of the following:'
    banner ''

    offset = Standup.scripts.keys.map(&:length).max + 2
    Standup.scripts.keys.sort.each do |name|
      banner "#{"%-#{offset}s" % name} #{Standup.scripts[name].description}"
    end

    banner ''
    banner "and [options] are:"
    banner ''

    stop_on Standup.scripts.keys
  end

  Trollop::with_standard_exception_handling opt_parser do
   opt_parser.parse ARGV
   raise Trollop::HelpNeeded if ARGV.empty?
  end

  script_name = ARGV.shift
  script = Standup.scripts[script_name]

  if script
    script.execute
  else
    opt_parser.die "unknown script #{script_name}", nil
  end
end

.script(type = :node, &block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/standup.rb', line 51

def self.script type = :node, &block
  name = eval("__FILE__", block.binding).match(/([^\/]*)\.rb$/)[1]
  superclass = scripts[name] || case type
    when :node
      Scripts::Node
    when :local
      Scripts::Base
    else
      raise ArgumentError, "Unknown script type #{type}"
  end
  script_class = Class.new(superclass, &block)
  script_class.name = name
  Standup::Scripts.send(:remove_const, name.camelize) if scripts[name]
  Standup::Scripts.const_set name.camelize, script_class
  scripts[name] = script_class
end

.scriptsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/standup.rb', line 37

def self.scripts
  unless class_variable_defined? :@@scripts
    @@scripts = {}
    [gem_scripts_path, conf_scripts_path, local_scripts_path].compact.each do |dir|
      Dir.foreach dir do |name|
        next unless File.file? "#{dir}/#{name}"
        next unless name =~ /\.rb$/
        load "#{dir}/#{name}", true
      end if dir && File.exists?(dir)
    end
  end
  @@scripts
end

.versionObject



4
5
6
# File 'lib/standup/version.rb', line 4

def self.version
  VERSION
end