launchd 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/README.md +7 -19
- data/launchd.gemspec +2 -0
- data/lib/launchd.rb +4 -1
- data/lib/launchd/service.rb +70 -0
- data/lib/launchd/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb752b754bb2198fdadd8ebbf74280e6f79aeaf
|
4
|
+
data.tar.gz: 1ec69bbdf2d510e349c1bfe4041cdebc8fcdd8fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e74098bed3e054e22185f09bf27528d1858186ca3042a05b4a3a69b4d0027ddc473a21e82f2ceae57bf31c27551653d9c8bdccc7ee592c13c43c0e3fcf74722d
|
7
|
+
data.tar.gz: a6fc55dcf1d6cbce2aa3726df13afb5b85bbd07364c0b8174c2f8dc07055e9e3107a8b4b2354eef26f93ac65019376634272532b53b64e473103ec7c79d43cc5
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
system
|
data/README.md
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
Ruby-Launchd is like launchctl (or the famous lunchy). It lets you easily
|
4
4
|
create, start and stop services on Mac OS X, but with Ruby.
|
5
5
|
|
6
|
-
**NOTE: This is currently just the README without any code!**
|
7
|
-
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
@@ -22,29 +20,19 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
$ gem install launchd
|
24
22
|
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
A new service requires a label (in reverse-domain-notation) and the actual
|
28
|
-
command to run as array:
|
29
23
|
|
30
|
-
|
31
|
-
service = Launchd.new 'com.example.chunkybacon', %w(/usr/sbin/chunkyd --bacon)
|
32
|
-
```
|
24
|
+
## Usage
|
33
25
|
|
34
|
-
|
26
|
+
Deploy (install & restart) a service:
|
35
27
|
|
36
28
|
```Ruby
|
37
|
-
service.
|
38
|
-
|
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
|
39
33
|
```
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
Use the bang-version to forcefully overwrite an already running service:
|
44
|
-
|
45
|
-
```Ruby
|
46
|
-
service.start! # Stops, updates and starts service, no matter if it's running or not.
|
47
|
-
```
|
35
|
+
**NOTE: All options are also required!**
|
48
36
|
|
49
37
|
|
50
38
|
## Development
|
data/launchd.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
+
spec.add_dependency 'plist', '~> 3.1'
|
23
|
+
|
22
24
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
26
|
spec.add_development_dependency 'rspec'
|
data/lib/launchd.rb
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
module Launchd
|
2
|
+
class Service
|
3
|
+
attr_reader :label
|
4
|
+
|
5
|
+
def initialize(label, opts = {})
|
6
|
+
@label = label
|
7
|
+
@opts = opts
|
8
|
+
end
|
9
|
+
|
10
|
+
# Deploy (install & restart) the service.
|
11
|
+
#
|
12
|
+
# If running as root, it will get installed as system-wide daemon,
|
13
|
+
# otherwise as agent.
|
14
|
+
#
|
15
|
+
def deploy
|
16
|
+
stop if running?
|
17
|
+
write_plist
|
18
|
+
start
|
19
|
+
end
|
20
|
+
|
21
|
+
# Stops the service.
|
22
|
+
def stop
|
23
|
+
system("launchctl unload -w #{label}")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Starts the service.
|
27
|
+
def start
|
28
|
+
system("launchctl load -w #{label}")
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns true, when this service is runnung (loaded), otherwise false.
|
32
|
+
def running?
|
33
|
+
!!system("launchctl list #{label}")
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Save actual plist to disk.
|
39
|
+
def write_plist
|
40
|
+
File.open(plist_path, 'w') do |file|
|
41
|
+
file.puts properties.to_plist
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns path to plist.
|
46
|
+
def plist_path
|
47
|
+
plist_dir.join "#{label}.plist"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns directory where plist is stored.
|
51
|
+
def plist_dir
|
52
|
+
Pathname.new(
|
53
|
+
root? ? '/Library/LaunchDaemons' : '~/Library/LaunchAgents')
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns true, when running as root, otherwise false.
|
57
|
+
def root?
|
58
|
+
Process.euid.zero?
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns hash of plist properties.
|
62
|
+
def properties
|
63
|
+
{
|
64
|
+
'Label' => label,
|
65
|
+
'ProgramArguments' => @opts[:program_arguments],
|
66
|
+
'KeepAlive' => @opts[:keep_alive]
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/launchd/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: launchd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.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-
|
11
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: plist
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +76,7 @@ extra_rdoc_files: []
|
|
62
76
|
files:
|
63
77
|
- .gitignore
|
64
78
|
- .rspec
|
79
|
+
- .ruby-version
|
65
80
|
- .travis.yml
|
66
81
|
- CODE_OF_CONDUCT.md
|
67
82
|
- Gemfile
|
@@ -72,6 +87,7 @@ files:
|
|
72
87
|
- bin/setup
|
73
88
|
- launchd.gemspec
|
74
89
|
- lib/launchd.rb
|
90
|
+
- lib/launchd/service.rb
|
75
91
|
- lib/launchd/version.rb
|
76
92
|
homepage: https://github.com/bjoernalbers/ruby-launchd
|
77
93
|
licenses:
|