lunchy 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.md +6 -0
- data/README.md +2 -1
- data/bin/lunchy +17 -8
- data/lib/lunchy.rb +53 -46
- metadata +22 -40
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fe9904b30b68e92d860ede29932192a4f8131c15
|
4
|
+
data.tar.gz: 173bd3acfad8b595e078dfa7fd5163e71595bc68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65ce72ab1bbe94e21883ba1bf5ba2e5924a596c10d083aa103e0840cc6a0bbedac9a0815d8c481605d329abc7d22a671db687f23e0952346c17960b653e367d2
|
7
|
+
data.tar.gz: a3c84055cce932ddb7a1530182cd639bfb0754c57c3385871798ffd97ac3da93535b268b9903c5c4bfeeca555a2e501b8cfdf93e77bc2fff25a604fddb176480
|
data/History.md
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,7 @@ Lunchy aims to be that friendly tool by wrapping launchctl and providing a few s
|
|
13
13
|
- restart [pattern]
|
14
14
|
- status [pattern]
|
15
15
|
- install [file]
|
16
|
+
- show [pattern]
|
16
17
|
- edit [pattern]
|
17
18
|
|
18
19
|
where pattern is just a substring that matches the agent's plist filename. If you don't use a unique pattern, Lunchy will warn you of this and give you a list of the matching items instead.
|
@@ -50,7 +51,7 @@ Thanks
|
|
50
51
|
|
51
52
|
Thanks to all the individual contributors who've improved Lunchy, see credits in History.md.
|
52
53
|
|
53
|
-
Lunchy was written as part of my project time at [Carbon Five](http://carbonfive.com). [
|
54
|
+
Lunchy was written as part of my project time at [Carbon Five](http://carbonfive.com). [They're hiring](http://carbonfive.com/view/page.basic/jobs) if you love working on Ruby and open source.
|
54
55
|
|
55
56
|
|
56
57
|
About
|
data/bin/lunchy
CHANGED
@@ -4,11 +4,12 @@ $LOAD_PATH << File.dirname(__FILE__) + "/../lib" if $0 == __FILE__
|
|
4
4
|
require 'optparse'
|
5
5
|
require 'lunchy'
|
6
6
|
|
7
|
-
CONFIG = {
|
8
|
-
OPERATIONS = %w(start stop restart ls list status install edit)
|
7
|
+
CONFIG = {}
|
8
|
+
OPERATIONS = %w(start stop restart ls list status install show edit)
|
9
9
|
|
10
10
|
option_parser = OptionParser.new do |opts|
|
11
|
-
opts.banner = "Lunchy #{Lunchy::VERSION}, the friendly launchctl wrapper\
|
11
|
+
opts.banner = "Lunchy #{Lunchy::VERSION}, the friendly launchctl wrapper\n" \
|
12
|
+
"Usage: #{File.basename(__FILE__)} [#{OPERATIONS.join('|')}] [options]"
|
12
13
|
|
13
14
|
opts.on("-F", "--force", "Force start (disabled) agents") do |verbose|
|
14
15
|
CONFIG[:force] = true
|
@@ -22,27 +23,35 @@ option_parser = OptionParser.new do |opts|
|
|
22
23
|
CONFIG[:write] = true
|
23
24
|
end
|
24
25
|
|
26
|
+
opts.on("-l", "--long", "Display absolute paths when listing agents") do
|
27
|
+
CONFIG[:long] = true
|
28
|
+
end
|
29
|
+
|
25
30
|
opts.separator <<-EOS
|
26
31
|
|
27
32
|
Supported commands:
|
28
33
|
|
29
|
-
ls [pattern]
|
30
|
-
list [pattern]
|
34
|
+
ls [-l] [pattern] Show the list of installed agents, with optional [pattern] filter
|
35
|
+
list [-l] [pattern] Alias for 'ls'
|
31
36
|
start [-wF] [pattern] Start the first agent matching [pattern]
|
32
37
|
stop [-w] [pattern] Stop the first agent matching [pattern]
|
33
38
|
restart [pattern] Stop and start the first agent matching [pattern]
|
34
39
|
status [pattern] Show the PID and label for all agents, with optional [pattern] filter
|
35
|
-
install [file]
|
36
|
-
|
40
|
+
install [file] Install [file] to ~/Library/LaunchAgents or /Library/LaunchAgents (whichever it finds first)
|
41
|
+
show [pattern] Show the contents of the launchctl daemon file
|
42
|
+
edit [pattern] Open the launchctl daemon file in the default editor (EDITOR environment variable)
|
37
43
|
|
38
44
|
-w will persist the start/stop command so the agent will load on startup or never load, respectively.
|
45
|
+
-l will display absolute paths of the launchctl daemon files when showing list of installed agents.
|
39
46
|
|
40
47
|
Example:
|
41
48
|
lunchy ls
|
49
|
+
lunchy ls -l nginx
|
42
50
|
lunchy start -w redis
|
43
51
|
lunchy stop mongo
|
44
52
|
lunchy status mysql
|
45
53
|
lunchy install /usr/local/Cellar/redis/2.2.2/io.redis.redis-server.plist
|
54
|
+
lunchy show redis
|
46
55
|
lunchy edit mongo
|
47
56
|
|
48
57
|
Note: if you run lunchy as root, you can manage daemons in /Library/LaunchDaemons also.
|
@@ -64,4 +73,4 @@ if OPERATIONS.include?(op)
|
|
64
73
|
end
|
65
74
|
else
|
66
75
|
puts option_parser.help
|
67
|
-
end
|
76
|
+
end
|
data/lib/lunchy.rb
CHANGED
@@ -1,35 +1,23 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
3
|
class Lunchy
|
4
|
-
VERSION = '0.
|
4
|
+
VERSION = '0.7.0'
|
5
5
|
|
6
6
|
def start(params)
|
7
7
|
raise ArgumentError, "start [-wF] [name]" if params.empty?
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
return puts "Multiple daemons found matching '#{name}'. You need to be more specific. Matches found are:\n" + files.keys.join("\n")
|
13
|
-
elsif files.size == 0
|
14
|
-
return puts "No daemon found matching '#{name}'" if !name
|
15
|
-
else
|
16
|
-
execute("launchctl load #{CONFIG[:force] ? '-F ' : ''}#{CONFIG[:write] ? '-w ' : ''}#{files.values.first.inspect}")
|
17
|
-
puts "started #{files.keys.first}"
|
8
|
+
|
9
|
+
with_match params[0] do |name, path|
|
10
|
+
execute("launchctl load #{force}#{write}#{path.inspect}")
|
11
|
+
puts "started #{name}"
|
18
12
|
end
|
19
13
|
end
|
20
14
|
|
21
15
|
def stop(params)
|
22
16
|
raise ArgumentError, "stop [-w] [name]" if params.empty?
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
return puts "Multiple daemons found matching '#{name}'. You need to be more specific. Matches found are:\n" + files.keys.join("\n")
|
28
|
-
elsif files.size == 0
|
29
|
-
return puts "No daemon found matching '#{name}'" if !name
|
30
|
-
else
|
31
|
-
execute("launchctl unload #{CONFIG[:write] ? '-w ' : ''}#{files.values.first.inspect}")
|
32
|
-
puts "stopped #{files.keys.first}"
|
17
|
+
|
18
|
+
with_match params[0] do |name, path|
|
19
|
+
execute("launchctl unload #{write}#{path.inspect}")
|
20
|
+
puts "stopped #{name}"
|
33
21
|
end
|
34
22
|
end
|
35
23
|
|
@@ -41,10 +29,12 @@ class Lunchy
|
|
41
29
|
def status(params)
|
42
30
|
pattern = params[0]
|
43
31
|
cmd = "launchctl list"
|
44
|
-
|
32
|
+
|
33
|
+
unless verbose?
|
45
34
|
agents = plists.keys.map { |k| "-e \"#{k}\"" }.join(" ")
|
46
35
|
cmd << " | grep -i #{agents}"
|
47
36
|
end
|
37
|
+
|
48
38
|
cmd.gsub!('.','\.')
|
49
39
|
cmd << " | grep -i \"#{pattern}\"" if pattern
|
50
40
|
execute(cmd)
|
@@ -53,7 +43,11 @@ class Lunchy
|
|
53
43
|
def ls(params)
|
54
44
|
agents = plists.keys
|
55
45
|
agents = agents.grep(/#{params[0]}/) if !params.empty?
|
56
|
-
|
46
|
+
if long
|
47
|
+
puts agents.map { |agent| plists[agent] }.sort.join("\n")
|
48
|
+
else
|
49
|
+
puts agents.sort.join("\n")
|
50
|
+
end
|
57
51
|
end
|
58
52
|
alias_method :list, :ls
|
59
53
|
|
@@ -68,27 +62,54 @@ class Lunchy
|
|
68
62
|
end
|
69
63
|
end
|
70
64
|
|
65
|
+
def show(params)
|
66
|
+
raise ArgumentError, "show [name]" if params.empty?
|
67
|
+
|
68
|
+
with_match params[0] do |_, path|
|
69
|
+
puts IO.read(path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
71
73
|
def edit(params)
|
72
74
|
raise ArgumentError, "edit [name]" if params.empty?
|
73
|
-
|
74
|
-
|
75
|
-
files = Hash[files] if files.is_a?(Array) # ruby 1.8
|
76
|
-
if files.size > 1
|
77
|
-
return puts "Multiple daemons found matching '#{name}'. You need to be more specific. Matches found are:\n" + files.keys.join("\n")
|
78
|
-
elsif files.size == 0
|
79
|
-
return puts "No daemon found matching '#{name}'" if !name
|
80
|
-
else
|
75
|
+
|
76
|
+
with_match params[0] do |_, path|
|
81
77
|
editor = ENV['EDITOR']
|
82
78
|
if editor.nil?
|
83
79
|
raise 'EDITOR environment variable is not set'
|
84
80
|
else
|
85
|
-
execute("#{editor} #{
|
81
|
+
execute("#{editor} #{path.inspect} > `tty`")
|
86
82
|
end
|
87
83
|
end
|
88
84
|
end
|
89
85
|
|
90
86
|
private
|
91
87
|
|
88
|
+
def force
|
89
|
+
CONFIG[:force] and '-F '
|
90
|
+
end
|
91
|
+
|
92
|
+
def write
|
93
|
+
CONFIG[:write] and '-w '
|
94
|
+
end
|
95
|
+
|
96
|
+
def long
|
97
|
+
CONFIG[:long]
|
98
|
+
end
|
99
|
+
|
100
|
+
def with_match name
|
101
|
+
files = plists.select {|k,_| k =~ /#{name}/i }
|
102
|
+
files = Hash[files] if files.is_a?(Array) # ruby 1.8
|
103
|
+
|
104
|
+
if files.size > 1
|
105
|
+
puts "Multiple daemons found matching '#{name}'. You need to be more specific. Matches found are:\n#{files.keys.join("\n")}"
|
106
|
+
elsif files.empty?
|
107
|
+
puts "No daemon found matching '#{name}'" unless name
|
108
|
+
else
|
109
|
+
yield(*files.to_a.first)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
92
113
|
def execute(cmd)
|
93
114
|
puts "Executing: #{cmd}" if verbose?
|
94
115
|
emitted = `#{cmd}`
|
@@ -117,20 +138,6 @@ class Lunchy
|
|
117
138
|
Process.euid == 0
|
118
139
|
end
|
119
140
|
|
120
|
-
# def daemons
|
121
|
-
# @daemons ||= begin
|
122
|
-
# content = `launchctl list | grep -v -i "^-\\|anonymous"`
|
123
|
-
# daemons = []
|
124
|
-
# content.each_line do |x|
|
125
|
-
# data = x.split(' ')
|
126
|
-
# daemons << {
|
127
|
-
# :pid => data[0].to_i,
|
128
|
-
# :name => data[2]
|
129
|
-
# }
|
130
|
-
# end
|
131
|
-
# end
|
132
|
-
# end
|
133
|
-
|
134
141
|
def verbose?
|
135
142
|
CONFIG[:verbose]
|
136
143
|
end
|
metadata
CHANGED
@@ -1,68 +1,50 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: lunchy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 6
|
8
|
-
- 0
|
9
|
-
version: 0.6.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Mike Perham
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2012-01-25 00:00:00 -08:00
|
18
|
-
default_executable:
|
11
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
19
12
|
dependencies: []
|
20
|
-
|
21
13
|
description: Friendly wrapper around launchctl
|
22
|
-
email:
|
14
|
+
email:
|
23
15
|
- mperham@gmail.com
|
24
|
-
executables:
|
16
|
+
executables:
|
25
17
|
- lunchy
|
26
18
|
extensions: []
|
27
|
-
|
28
19
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
20
|
+
files:
|
31
21
|
- History.md
|
32
22
|
- LICENSE
|
33
23
|
- README.md
|
34
24
|
- bin/lunchy
|
35
25
|
- lib/lunchy.rb
|
36
26
|
- lunchy.gemspec
|
37
|
-
has_rdoc: true
|
38
27
|
homepage: http://github.com/mperham/lunchy
|
39
28
|
licenses: []
|
40
|
-
|
29
|
+
metadata: {}
|
41
30
|
post_install_message:
|
42
31
|
rdoc_options: []
|
43
|
-
|
44
|
-
require_paths:
|
32
|
+
require_paths:
|
45
33
|
- lib
|
46
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
requirements:
|
48
|
-
- -
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
60
44
|
requirements: []
|
61
|
-
|
62
45
|
rubyforge_project:
|
63
|
-
rubygems_version:
|
46
|
+
rubygems_version: 2.0.2
|
64
47
|
signing_key:
|
65
|
-
specification_version:
|
48
|
+
specification_version: 4
|
66
49
|
summary: Friendly wrapper around launchctl
|
67
50
|
test_files: []
|
68
|
-
|