Class: Launchd::Service
- Inherits:
-
Object
- Object
- Launchd::Service
- Defined in:
- lib/launchd/service.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
-
#deploy ⇒ Object
Deploy (install & restart) the service.
-
#initialize(label, opts = {}) ⇒ Service
constructor
A new instance of Service.
-
#running? ⇒ Boolean
Returns true, when this service is runnung (loaded), otherwise false.
-
#start ⇒ Object
Starts the service.
-
#stop ⇒ Object
Stops the service.
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
#label ⇒ Object (readonly)
Returns the value of attribute label.
3 4 5 |
# File 'lib/launchd/service.rb', line 3 def label @label end |
Instance Method Details
#deploy ⇒ Object
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.
32 33 34 |
# File 'lib/launchd/service.rb', line 32 def running? !!system("launchctl list #{label}") end |
#start ⇒ Object
Starts the service.
27 28 29 |
# File 'lib/launchd/service.rb', line 27 def start system("launchctl load -w #{label}") end |
#stop ⇒ Object
Stops the service.
22 23 24 |
# File 'lib/launchd/service.rb', line 22 def stop system("launchctl unload -w #{label}") end |