Class: Launchd::Service

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, opts = {}) ⇒ Service

Returns a new instance of Service.



5
6
7
8
# File 'lib/launchd/service.rb', line 5

def initialize(label, opts = {})
  @label = label
  @opts = opts
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/launchd/service.rb', line 3

def label
  @label
end

Instance Method Details

#deployObject

Deploy (install & restart) the service.

If running as root, it will get installed as system-wide daemon, otherwise as agent.



15
16
17
18
19
# File 'lib/launchd/service.rb', line 15

def deploy
  stop if running?
  write_plist
  start
end

#running?Boolean

Returns true, when this service is runnung (loaded), otherwise false.

Returns:

  • (Boolean)


32
33
34
# File 'lib/launchd/service.rb', line 32

def running?
  !!system("launchctl list #{label}")
end

#startObject

Starts the service.



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

def start
  system("launchctl load -w #{label}")
end

#stopObject

Stops the service.



22
23
24
# File 'lib/launchd/service.rb', line 22

def stop
  system("launchctl unload -w #{label}")
end