Module: RShare::Exec

Defined in:
lib/rshare/exec.rb

Class Method Summary collapse

Class Method Details

.run!(args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rshare/exec.rb', line 5

def self.run!(args)
  $opts = Options.parse!(args)

  if ARGV.length < 2 or ARGV.first !~ /^push|pull$/
    # Invalid arguments: Pretend the user asked for help
    Options.parse! %w{--help}
  end

  # Log to $stdout by default
  $log = Logger.new($stdout, shift_age = 'weekly')
  $log.level = $opts[:verbose] ? Logger::DEBUG : Logger::INFO

  # Daemonize if asked to
  if $opts[:daemon]
    $stdout.reopen File.open("./rshare.log", 'a')
    Process.daemon(nochdir=true, noclose=true)
    $log.info "Daemonized with PID #{Process.pid}"
  end

  confs = ARGV[1, ARGV.length].map { |f| Configuration.load(f) }
  confs.each { |c| ARGV.first =~ /push/ ? RSync.push!(c) : RSync.pull!(c) }

  $log.info "Exiting (PID #{Process.pid})"
end