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.
-
#options ⇒ Object
(also: #to_hash)
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Service
constructor
NOTE: Only label and program_arguments are required.
-
#restart ⇒ Object
restart (install & restart) the 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(opts = {}) ⇒ Service
NOTE: Only label and program_arguments are required. See ‘man launchd.plist` for all possible properties.
8 9 10 11 |
# File 'lib/launchd/service.rb', line 8 def initialize(opts = {}) = opts @label = opts.fetch(:label) 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 |
#options ⇒ Object (readonly) Also known as: to_hash
Returns the value of attribute options.
3 4 5 |
# File 'lib/launchd/service.rb', line 3 def end |
Instance Method Details
#restart ⇒ Object
restart (install & restart) the service.
If running as root, it will get installed as system-wide daemon, otherwise as agent.
18 19 20 21 22 |
# File 'lib/launchd/service.rb', line 18 def restart stop if running? save start end |
#running? ⇒ Boolean
Returns true, when this service is runnung (loaded), otherwise false.
35 36 37 |
# File 'lib/launchd/service.rb', line 35 def running? !!system("launchctl list #{label}") end |
#start ⇒ Object
Starts the service.
30 31 32 |
# File 'lib/launchd/service.rb', line 30 def start system("launchctl load -w #{label}") end |
#stop ⇒ Object
Stops the service.
25 26 27 |
# File 'lib/launchd/service.rb', line 25 def stop system("launchctl unload -w #{label}") end |