Class: Henchman::LaunchdHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/launchd_handler.rb

Class Method Summary collapse

Class Method Details

.internet_connection?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/launchd_handler.rb', line 45

def self.internet_connection?
  begin
    true if open("https://www.dropbox.com/")
  rescue
    false
  end
end

.startObject



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

def self.start
  if !internet_connection?
    puts "No internet connection detected - unable to verify correct configuration."
    return if !agree("Launch henchman anyways? (y/n) ")
  else
    puts "Checking configuration"
    return if !Henchman.connect
  end

  puts "Creating agent"
  plist      = Henchman::Templates.plist
  plist_path = File.expand_path("~/Library/LaunchAgents/com.henchman.plist")
  shell_script_path = File.expand_path("~/.henchman/run.sh")
  cache_path        = File.expand_path("~/.henchman/cache")
  File.write(plist_path, plist)
  File.write(shell_script_path, Henchman::Templates.shell_script)
  File.open(cache_path, "w") { |f| f.write( {}.to_yaml ) }

  puts "Launching agent"
  `chmod +x #{shell_script_path}`
  `launchctl load #{plist_path}`

  puts "Launched successful! You are now running henchman."
end

.stopObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/launchd_handler.rb', line 32

def self.stop
  puts "Stopping agents"
  plist_path = File.expand_path("~/Library/LaunchAgents/com.henchman.plist")
  `launchctl unload #{plist_path}`
  `rm #{plist_path}`
  `rm #{File.expand_path("~/.henchman/run.sh")}`
  `rm #{File.expand_path("~/.henchman/cache")}`
  `rm #{File.expand_path("~/.henchman/stdout.log")}`
  `rm #{File.expand_path("~/.henchman/stderr.log")}`

  puts "Successfully stopped henchman"
end