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
|
# File 'lib/ey_enzyme/cli.rb', line 5
def self.run(args)
$stdout.sync = true
defaults = {
chef_bin: 'chef-client',
run_list: ['recipe[ey-init::main]'],
config: '/etc/engineyard/dracul.yml',
base_path: '/etc/chef/',
logfile: '/var/log/ey-enzyme.log',
log_level: :info,
keep: 5,
run_custom: true,
download: true,
mode: :deploy
}
options = {}
opts = OptionParser.new do |opts|
opts.version = EY::Enzyme::VERSION
opts.banner = "Usage: ey-enzyme <options> [argument]"
opts.define_head "ey-enzyme: running recipes..."
opts.separator '*'*80
opts.on("--logfile", "Set the logfile (default: #{defaults[:logfile]})") do |path|
options[:logfile] = path
end
opts.on("--config CONFIG", "Use config file (default: #{defaults[:config]})") do |config|
options[:config] = config
end
opts.on("--cookbooks PATH", "Use the given path for retrieving and using the cookbooks (default: #{defaults[:base_path]}") do |path|
options[:base_path] = path
end
opts.on("--chef-bin PATH", "Use this chef-solo executable to run recipes") do |binary|
options[:chef_bin] = binary
end
opts.on("--run-list RECIPES", "Comma-separated list of recipes to run") do |recipe_list|
options[:run_list] = recipe_list.split(',').collect {|r| "recipe[#{r}]" }
end
opts.on("--report message", "Report a status") do |message|
options[:mode] = :report
options[:message] = message
end
opts.on("--no-custom", "Do not overlay custom recipes") do
options[:run_custom] = false
end
opts.on("--cached", "Used the cached version of the cookbooks and dna.json") do
options[:download] = false
end
opts.on("--refresh-dna", "Write new dna even if --cached is on") do
options[:refresh_dna] = true
end
opts.on("--verbose", "Show debug logs as well") do
options[:log_level] = :debug
end
end
opts.parse!(args)
config = options[:config] || defaults[:config]
cli = new(defaults.merge(YAML.load_file(config)).merge(options))
if options[:mode] == :report
cli.report(options[:message])
else
cli.deploy
end
rescue OptionParser::InvalidOption
$stderr.puts "#{File.basename($0)} #{$!.message}"
abort opts.to_s
rescue *IGNORABLE_EXCEPTIONS
raise
rescue DeployError
if cli
cli.report $!.message
cli.notify_user_error($!)
exit 0
end
raise
rescue DNAError
if cli
cli.report $!.message
cli.notify_system_error($!)
exit 0
end
raise
rescue Exception
if cli
cli.notify_system_error($!)
exit 0
end
raise
end
|