lunchy 0.2.0 → 0.3.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.
Files changed (4) hide show
  1. data/History.md +5 -0
  2. data/bin/lunchy +18 -10
  3. data/lib/lunchy.rb +28 -13
  4. metadata +5 -6
data/History.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Changes
2
2
  ================
3
3
 
4
+ 0.3.0
5
+ - New 'install' command to install new plist files (spagalloco)
6
+ - Support persistent start/stop
7
+ - Fix Ruby 1.8 issues, thanks tmm1!
8
+
4
9
  0.2.0
5
10
  - Only show agents with plists by default (fhemberger)
6
11
  - Warn and stop if pattern matches multiple agents (andyjeffries)
data/bin/lunchy CHANGED
@@ -4,8 +4,8 @@ $LOAD_PATH << File.dirname(__FILE__) + "/../lib" if $0 == __FILE__
4
4
  require 'optparse'
5
5
  require 'lunchy'
6
6
 
7
- CONFIG = { :verbose => false }
8
- OPERATIONS = %w(start stop restart ls list status)
7
+ CONFIG = { :verbose => false, :write => false }
8
+ OPERATIONS = %w(start stop restart ls list status install)
9
9
 
10
10
  option_parser = OptionParser.new do |opts|
11
11
  opts.banner = "Lunchy #{Lunchy::VERSION}, the friendly launchctl wrapper\nUsage: #{__FILE__} [#{OPERATIONS.join('|')}] [options]"
@@ -13,23 +13,31 @@ option_parser = OptionParser.new do |opts|
13
13
  opts.on("-v", "--verbose", "Show command executions") do |verbose|
14
14
  CONFIG[:verbose] = true
15
15
  end
16
-
16
+
17
+ opts.on("-w", "--write", "Persist command") do |verbose|
18
+ CONFIG[:write] = true
19
+ end
20
+
17
21
  opts.separator <<-EOS
18
22
 
19
23
  Supported commands:
20
24
 
21
- ls [pattern] Show the list of installed agents, with optional [pattern] filter
22
- list [pattern] Alias for 'ls'
23
- start [pattern] Start the first agent matching [pattern]
24
- stop [pattern] Stop the first agent matching [pattern]
25
- restart [pattern] Stop and start the first agent matching [pattern]
26
- status [pattern] Show the PID and label for all agents, with optional [pattern] filter
25
+ ls [pattern] Show the list of installed agents, with optional [pattern] filter
26
+ list [pattern] Alias for 'ls'
27
+ start [-w] [pattern] Start the first agent matching [pattern]
28
+ stop [-w] [pattern] Stop the first agent matching [pattern]
29
+ restart [pattern] Stop and start the first agent matching [pattern]
30
+ status [pattern] Show the PID and label for all agents, with optional [pattern] filter
31
+ install [file] Installs [file] to ~/Library/LaunchAgents or /Library/LaunchAgents (whichever it finds first)
32
+
33
+ -w will persist the start/stop command so the agent will load on startup or never load, respectively.
27
34
 
28
35
  Example:
29
36
  lunchy ls
30
- lunchy start redis
37
+ lunchy start -w redis
31
38
  lunchy stop mongo
32
39
  lunchy status mysql
40
+ lunchy install /usr/local/Cellar/redis/2.2.2/io.redis.redis-server.plist
33
41
  EOS
34
42
  end
35
43
  option_parser.parse!
@@ -1,35 +1,39 @@
1
+ require 'fileutils'
2
+
1
3
  class Lunchy
2
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
3
5
 
4
6
  def start(params)
5
- raise ArgumentError, "start [name]" if params.empty?
7
+ raise ArgumentError, "start [-w] [name]" if params.empty?
6
8
  name = params[0]
7
9
  files = plists.select {|k,v| k =~ /#{name}/i }
8
- if files.length > 1
10
+ files = Hash[files] if files.is_a?(Array) # ruby 1.8
11
+ if files.size > 1
9
12
  return puts "Multiple daemons found matching '#{name}'. You need to be more specific. Matches found are:\n" + files.keys.join("\n")
10
- elsif files.length == 0
13
+ elsif files.size == 0
11
14
  return puts "No daemon found matching '#{name}'" if !name
12
15
  else
13
- execute("launchctl load #{files.values.first.inspect}")
16
+ execute("launchctl load #{CONFIG[:write] ? '-w ' : ''}#{files.values.first.inspect}")
14
17
  end
15
18
  end
16
19
 
17
20
  def stop(params)
18
- raise ArgumentError, "stop [name]" if params.empty?
21
+ raise ArgumentError, "stop [-w] [name]" if params.empty?
19
22
  name = params[0]
20
23
  files = plists.select {|k,v| k =~ /#{name}/i }
21
- if files.length > 1
24
+ files = Hash[files] if files.is_a?(Array) # ruby 1.8
25
+ if files.size > 1
22
26
  return puts "Multiple daemons found matching '#{name}'. You need to be more specific. Matches found are:\n" + files.keys.join("\n")
23
- elsif files.length == 0
27
+ elsif files.size == 0
24
28
  return puts "No daemon found matching '#{name}'" if !name
25
29
  else
26
- execute("launchctl unload #{files.values.first.inspect}")
30
+ execute("launchctl unload #{CONFIG[:write] ? '-w ' : ''}#{files.values.first.inspect}")
27
31
  end
28
32
  end
29
33
 
30
34
  def restart(params)
31
- stop(params)
32
- start(params)
35
+ stop(params.dup)
36
+ start(params.dup)
33
37
  end
34
38
 
35
39
  def status(params)
@@ -42,14 +46,25 @@ class Lunchy
42
46
  cmd << " | grep -i \"#{pattern}\"" if pattern
43
47
  execute(cmd)
44
48
  end
45
-
49
+
46
50
  def ls(params)
47
51
  agents = plists.keys
48
52
  agents = agents.grep(/#{params[0]}/) if !params.empty?
49
53
  puts agents.sort.join("\n")
50
54
  end
51
55
  alias_method :list, :ls
52
-
56
+
57
+ def install(params)
58
+ raise ArgumentError, "install [file]" if params.empty?
59
+ filename = params[0]
60
+ %w(~/Library/LaunchAgents /Library/LaunchAgents).each do |dir|
61
+ if Dir.exist?(File.expand_path(dir))
62
+ FileUtils.cp filename, File.join(File.expand_path(dir), File.basename(filename))
63
+ return puts "#{filename} installed to #{dir}"
64
+ end
65
+ end
66
+ end
67
+
53
68
  private
54
69
 
55
70
  def execute(cmd)
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lunchy
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.0
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mike Perham
@@ -10,7 +9,7 @@ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2011-03-29 00:00:00 -07:00
12
+ date: 2011-03-31 00:00:00 -07:00
14
13
  default_executable:
15
14
  dependencies: []
16
15
 
@@ -40,21 +39,21 @@ rdoc_options: []
40
39
  require_paths:
41
40
  - lib
42
41
  required_ruby_version: !ruby/object:Gem::Requirement
43
- none: false
44
42
  requirements:
45
43
  - - ">="
46
44
  - !ruby/object:Gem::Version
47
45
  version: "0"
46
+ version:
48
47
  required_rubygems_version: !ruby/object:Gem::Requirement
49
- none: false
50
48
  requirements:
51
49
  - - ">="
52
50
  - !ruby/object:Gem::Version
53
51
  version: "0"
52
+ version:
54
53
  requirements: []
55
54
 
56
55
  rubyforge_project:
57
- rubygems_version: 1.6.2
56
+ rubygems_version: 1.3.5
58
57
  signing_key:
59
58
  specification_version: 3
60
59
  summary: Friendly wrapper around launchctl