Module: LaunchDoctor

Extended by:
LaunchDoctor
Included in:
LaunchDoctor
Defined in:
lib/launchdr.rb,
lib/launchdr/tasks.rb,
lib/launchdr/launchd.rb,
lib/launchdr/property_list.rb

Defined Under Namespace

Classes: Launchd, PropertyList

Constant Summary collapse

Version =
0
Options =
Hash.new

Instance Method Summary collapse

Instance Method Details

#allow_system_agents!Object



27
28
29
# File 'lib/launchdr.rb', line 27

def allow_system_agents!
  Options[:system_agents_allowed] = true
end

#allow_system_daemons!Object



31
32
33
34
# File 'lib/launchdr.rb', line 31

def allow_system_daemons!
  raise "You must allow System-owned agents to allow System-owned daemons!" unless Options[:system_agents_allowed]
  Options[:system_daemon_allowed] = true
end

#create(label, opts = {}) {|plist| ... } ⇒ Object

Yields:

  • (plist)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/launchdr.rb', line 14

def create label, opts = {}
  plist = Launchd.new label
  
  yield plist if block_given?
  
  raise "You must run as a root user and allow_system_agents! if you wish to preform the dangerous act of writing to #{Launchd::Paths[:system_agent]}!" unless !(opts[:type] == :system_agent) or Options[:system_agents_allowed]
  raise "You must run as a root user, allow_system_agents!, *and* allow_system_daemons! if you wish to preform the very dangerous act of writing to #{Launchd::Paths[:system_daemon]}!" unless !(opts[:type] == :system_daemon) or Options[:system_daemon_allowed]
  path = Launchd::Paths[opts[:type] || :user_agent]
  raise "Type error! Must be one of #{Launchd::Paths.keys.join(", ")}" unless path
  
  plist.dump File.expand_path(path)
end

#task(name = :launchd, opts = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/launchdr/tasks.rb', line 3

def task name = :launchd, opts = {}
  raise "`LaunchDoctor.task`'s options must include the name of the binary for your gem!" unless opts[:bin]
  opts = {:desc => 'Creates a launchd property list for this gem', :arguments => []}.merge opts
  
  desc opts[:desc] unless opts[:no_desc]
  task name do
    LaunchDoctor label do |plist|
      plist[:program_arguments] = [File.join('/usr/local/bin', opts[:bin]), opts[:arguments]].flatten
      plist[:keep_alive] = true
      plist[:run_at_load] = true
    end
  end
  
end