Class: Capricorn::CLI::Applications
Constant Summary
Constants included
from Helpers
Helpers::DEFAULT_CONFIG
Instance Method Summary
collapse
Methods included from Helpers
#application, #application_ids, #application_info, #applications, #client, #cluster, #config, #environment, #halt, #info, #local_config, #machine, #machines, #node, #nodes
banner, #help, #method_missing, start
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Capricorn::CLI
Instance Method Details
#create(name, environment, *domains) ⇒ Object
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
|
# File 'lib/capricorn-client/cli/applications.rb', line 55
def create(name, environment, *domains)
name = name.to_s.strip
if name.empty?
halt "Please choose a name!"
end
environment = environment.to_s.strip
unless %w( production development staging testing ).include?(environment)
halt "Please select a valid environment!"
end
environment = environment.to_sym
domains = domains.flatten do |domain|
if domain
domain = domain.to_s.downcase.strip.sub(/^www\./, '')
begin
PublicSuffixService.parse(domain).to_s
rescue Exception
halt "invalid domain: #{domain}"
end
end
end.compact.uniq
domains.delete('')
if domains.empty?
halt "Please add at least one domain!"
end
p client.call.applications.create(machine.to_sym, name, domains, environment)
end
|
154
155
156
157
|
# File 'lib/capricorn-client/cli/applications.rb', line 154
def fupdate
machine, id = *application
p client.call.applications.fupdate(machine.to_sym, id)
end
|
#import(name, environment, *domains) ⇒ Object
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
|
# File 'lib/capricorn-client/cli/applications.rb', line 86
def import(name, environment, *domains)
root = File.expand_path(Dir.pwd)
unless File.file?(File.join(root, "host/config/milkshake.yml"))
info 'no milkshake config was found'
halt 'This doesn\'t appear to be a milkshake app!'
end
unless File.directory?(File.join(root, "shared"))
info 'no shared dir was found'
halt 'This doesn\'t appear to be a milkshake app!'
end
gems = YAML.load_file(File.join(root, "host/config/milkshake.yml"))
gems = (gems['gems'].keys rescue [])
if gems.empty?
info 'no gems were found'
halt 'This doesn\'t appear to be a milkshake app!'
end
stats = (File.stat(File.join(root, "host/config/environment.rb")) rescue nil)
unless stats
info 'no environment.rb was found'
halt 'This doesn\'t appear to be a milkshake app!'
end
uid = (Etc.getpwuid(stats.uid).name rescue nil)
unless uid
info 'no uid was found'
halt 'This doesn\'t appear to be a milkshake app!'
end
gid = (Etc.getgrgid(stats.gid).name rescue nil)
unless gid
info 'no gid was found'
halt 'This doesn\'t appear to be a milkshake app!'
end
name = name.to_s.strip
if name.empty?
halt "Please choose a name!"
end
environment = environment.to_s.strip
unless %w( production development staging testing ).include?(environment)
halt "Please select a valid environment!"
end
environment = environment.to_sym
domains = domains.flatten do |domain|
if domain
domain = domain.to_s.downcase.strip.sub(/^www\./, '')
begin
PublicSuffixService.parse(domain).to_s
rescue Exception
halt "invalid domain: #{domain}"
end
end
end.compact.uniq
domains.delete('')
if domains.empty?
halt "Please add at least one domain!"
end
p client.call.applications.import(machine.to_sym, name, domains, environment, root, gems, uid, gid)
end
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/capricorn-client/cli/applications.rb', line 10
def init
if File.file?('.capricorn.yml')
halt ".capricorn.yml already exists"
end
File.open(".capricorn.yml", 'w+') do |file|
file.write <<-EOS
staging:
cluster: CLUSTER_NAME
machine: MACHINE_ID
application: APPLICATION_ID
EOS
end
info "initialized .capricorn.yml"
end
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/capricorn-client/cli/applications.rb', line 27
def list
apps = client.call.applications.all(machine.to_sym).last || []
apps.collect! do |app|
[app[3], app[1]]
end
apps.sort! do |a,b|
a[0] <=> b[0]
end
width = apps.inject(0) { |m, (n, _)| (m > n.size ? m : n.size) }
apps.each do |(name, id)|
padding = ' ' * (width - name.size)
puts "#{name}#{padding} : #{id}"
end
end
|
160
161
162
163
|
# File 'lib/capricorn-client/cli/applications.rb', line 160
def relink
machine, id = *application
p client.call.applications.relink(machine.to_sym, id)
end
|
166
167
168
169
|
# File 'lib/capricorn-client/cli/applications.rb', line 166
def restart
machine, id = *application
p client.call.applications.restart(machine.to_sym, id)
end
|
44
45
46
47
48
49
50
51
52
|
# File 'lib/capricorn-client/cli/applications.rb', line 44
def show
puts " Id: #{application_info[1]}"
puts " Machine: #{application_info[2]}"
puts " Name: #{application_info[3]}"
puts " Environment: #{application_info[5]}"
puts " User: #{application_info[6]}"
puts " Group: #{application_info[7]}"
puts " Root: #{application_info[8]}"
end
|
172
173
174
175
|
# File 'lib/capricorn-client/cli/applications.rb', line 172
def start
machine, id = *application
p client.call.applications.start(machine.to_sym, id)
end
|
178
179
180
181
|
# File 'lib/capricorn-client/cli/applications.rb', line 178
def stop
machine, id = *application
p client.call.applications.stop(machine.to_sym, id)
end
|