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 +4 -4
- data/README.md +15 -6
- data/lib/launchd/service.rb +19 -14
- data/lib/launchd/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc9bd564abaac27b427b343ca88cfcb460137aba
|
4
|
+
data.tar.gz: 89db52cc37d76564f897123c3957d5a1b11780c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
26
|
+
Initialize a service object:
|
27
27
|
|
28
28
|
```Ruby
|
29
|
-
service = Launchd::Service.new
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
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
|
data/lib/launchd/service.rb
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
module Launchd
|
2
2
|
class Service
|
3
|
-
attr_reader :label
|
3
|
+
attr_reader :options, :label
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
#
|
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
|
18
|
+
def restart
|
16
19
|
stop if running?
|
17
|
-
|
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
|
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
|
66
|
+
# Returns hash of properties with CamelCase-keys.
|
62
67
|
def properties
|
63
|
-
{
|
64
|
-
'
|
65
|
-
|
66
|
-
|
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
|
data/lib/launchd/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plist
|