Class: BackupDemon::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/backup_demon/cli.rb

Instance Method Summary collapse

Instance Method Details

#reloadObject



58
59
60
# File 'lib/backup_demon/cli.rb', line 58

def reload
  load_config
end

#start(directories = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/backup_demon/cli.rb', line 18

def start(directories = nil)
  load_config
  
  directories = directories.to_s.split(',').map(&:strip) unless directories.nil?

  daemon = BackupDemon::Daemon.new(
    directories || BackupDemon.config.directories, 
    BackupDemon.config.device, 
    BackupDemon.config.mount
  )

  if BackupDemon.config.daemon
    Process.daemon(true)
  end

  if BackupDemon.config.pid
    File.open(BackupDemon.config.pid, 'w') { |f| f << daemon.pid }
  end

  daemon.run!(BackupDemon.config.interval)
end

#stop(pid = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/backup_demon/cli.rb', line 42

def stop(pid = nil)
  load_config
  pidfile = BackupDemon.config.pid

  if pidfile && File.exists?(pidfile)
    File.foreach(pidfile) do |pid|
      begin
        Process.kill("KILL", pid.to_i)
      rescue
        puts "Nothing to stop"
      end
    end
  end
end