Class: Vines::Agent::Command::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/vines/agent/command/init.rb

Instance Method Summary collapse

Instance Method Details

#run(opts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vines/agent/command/init.rb', line 7

def run(opts)
  raise 'vines-agent init <domain>' unless opts[:args].size == 1
  domain = opts[:args].first.downcase
  dir = File.expand_path(domain)
  raise "Directory already initialized: #{domain}" if File.exists?(dir)
  Dir.mkdir(dir)

  FileUtils.cp_r(File.expand_path("../../../../../conf", __FILE__), dir)

  data, log, pid = %w[data log pid].map do |sub|
    File.join(dir, sub).tap {|subdir| Dir.mkdir(subdir) }
  end

  update_config(domain, File.expand_path('conf/config.rb', dir))
  fix_perms(dir)

  puts "Initialized agent directory: #{domain}"
  puts "Run 'cd #{domain} && vines-agent start' to begin"
end