launchd 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fb752b754bb2198fdadd8ebbf74280e6f79aeaf
4
- data.tar.gz: 1ec69bbdf2d510e349c1bfe4041cdebc8fcdd8fe
3
+ metadata.gz: dc9bd564abaac27b427b343ca88cfcb460137aba
4
+ data.tar.gz: 89db52cc37d76564f897123c3957d5a1b11780c8
5
5
  SHA512:
6
- metadata.gz: e74098bed3e054e22185f09bf27528d1858186ca3042a05b4a3a69b4d0027ddc473a21e82f2ceae57bf31c27551653d9c8bdccc7ee592c13c43c0e3fcf74722d
7
- data.tar.gz: a6fc55dcf1d6cbce2aa3726df13afb5b85bbd07364c0b8174c2f8dc07055e9e3107a8b4b2354eef26f93ac65019376634272532b53b64e473103ec7c79d43cc5
6
+ metadata.gz: cdd324002213f700174868512b6236063029a823efacb4257ce8e1358e92e5e32cbd4fefb3df3c94e76b9c9a353cb23ed749293286c64dfc70102c7d2cd2cade
7
+ data.tar.gz: a9dc1551d22ae89ad25bc86cf28633514a43e97e25baea7cfd2b51d652b006ca2842c1ea9bf23f0dd41d39291193efc314610f1ace2ea200375f3d8393578c46
data/README.md CHANGED
@@ -23,16 +23,25 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
- Deploy (install & restart) a service:
26
+ Initialize a service object:
27
27
 
28
28
  ```Ruby
29
- service = Launchd::Service.new 'com.example.chunkybacon', # Label of service
30
- program_arguments: %w(/usr/sbin/chunkyd --bacon), # command line as array
31
- keep_alive: true # Shall launchd keep it running?
32
- service.deploy
29
+ service = Launchd::Service.new,
30
+ label: 'com.example.chunkybacon', # Required
31
+ program_arguments: %w(/usr/sbin/chunkyd --bacon), # Required
32
+ keep_alive: true # Optional
33
33
  ```
34
34
 
35
- **NOTE: All options are also required!**
35
+ Only *label* and *program_arguments* are required. See
36
+ [`man launchd.plist(5)`](https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html)
37
+ for all possible properties.
38
+
39
+ Then stop, overwrite and start the service with the given properties (i.e. for
40
+ deployment):
41
+
42
+ ```Ruby
43
+ service.restart
44
+ ```
36
45
 
37
46
 
38
47
  ## Development
@@ -1,20 +1,23 @@
1
1
  module Launchd
2
2
  class Service
3
- attr_reader :label
3
+ attr_reader :options, :label
4
4
 
5
- def initialize(label, opts = {})
6
- @label = label
7
- @opts = opts
5
+ # NOTE: Only *label* and *program_arguments* are required.
6
+ # See `man launchd.plist` for all possible properties.
7
+ #
8
+ def initialize(opts = {})
9
+ @options = opts
10
+ @label = opts.fetch(:label)
8
11
  end
9
12
 
10
- # Deploy (install & restart) the service.
13
+ # restart (install & restart) the service.
11
14
  #
12
15
  # If running as root, it will get installed as system-wide daemon,
13
16
  # otherwise as agent.
14
17
  #
15
- def deploy
18
+ def restart
16
19
  stop if running?
17
- write_plist
20
+ save
18
21
  start
19
22
  end
20
23
 
@@ -33,10 +36,12 @@ module Launchd
33
36
  !!system("launchctl list #{label}")
34
37
  end
35
38
 
39
+ alias_method :to_hash, :options
40
+
36
41
  private
37
42
 
38
43
  # Save actual plist to disk.
39
- def write_plist
44
+ def save
40
45
  File.open(plist_path, 'w') do |file|
41
46
  file.puts properties.to_plist
42
47
  end
@@ -58,13 +63,13 @@ module Launchd
58
63
  Process.euid.zero?
59
64
  end
60
65
 
61
- # Returns hash of plist properties.
66
+ # Returns hash of properties with CamelCase-keys.
62
67
  def properties
63
- {
64
- 'Label' => label,
65
- 'ProgramArguments' => @opts[:program_arguments],
66
- 'KeepAlive' => @opts[:keep_alive]
67
- }
68
+ options.inject({}) do |memo, (k,v)|
69
+ camel_cased_key = k.to_s.split('_').map(&:capitalize).join
70
+ memo[camel_cased_key] = v
71
+ memo
72
+ end
68
73
  end
69
74
  end
70
75
  end
@@ -1,3 +1,3 @@
1
1
  module Launchd
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: launchd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Björn Albers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-26 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plist