mongrel-manager 0.0.1

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 (3) hide show
  1. data/README +1 -0
  2. data/bin/mongrel-manager +140 -0
  3. metadata +86 -0
data/README ADDED
@@ -0,0 +1 @@
1
+ Script for managing multiple local mongrel instances for local development of many projects.
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'trollop'
5
+ require 'hirb'
6
+ require 'pathname'
7
+ require 'ostruct'
8
+ require 'yaml'
9
+
10
+ def returning( object )
11
+ yield object
12
+ object
13
+ end
14
+
15
+ class MongrelInstance
16
+ attr :name, true
17
+ attr :port, true
18
+ attr :root, true
19
+
20
+ def initialize( name, port, root )
21
+ @name = name
22
+ @port = port
23
+ @root = root
24
+ end
25
+
26
+ def to_hash
27
+ {
28
+ :name => @name,
29
+ :port => @port,
30
+ :root => @root,
31
+ :status => status
32
+ }
33
+ end
34
+
35
+ def start
36
+ zap if status == 'stale'
37
+
38
+ `mongrel_rails start -p #{port} -c #{root} -p #{pidfile} -d`
39
+ sleep 5
40
+ if status != 'running'
41
+ STDERR.puts "Error starting mongrel, check the log file from #{root}/log/mongrel.log"
42
+ false
43
+ else
44
+ true
45
+ end
46
+ end
47
+
48
+ def stop
49
+ unless status == 'running'
50
+ puts "Instance is not running."
51
+ return false
52
+ end
53
+
54
+ `mongrel_rails stop -c #{root} -p #{pidfile}`
55
+ sleep 5
56
+ status != 'running'
57
+ end
58
+
59
+ def restart
60
+ stop && start
61
+ start
62
+ end
63
+
64
+ def zap
65
+ File.rm( pidfile )
66
+ end
67
+
68
+ def pidfile
69
+ @pidfile ||= File.join( root, 'log', 'mongrel.pid')
70
+ end
71
+
72
+ def status
73
+ if File.exists?( pidfile )
74
+ begin
75
+ Process.getpgid( File.read( pidfile ).to_i )
76
+ 'running'
77
+ rescue Errno::ESRCH
78
+ 'stale'
79
+ end
80
+ else
81
+ 'not running'
82
+ end
83
+ end
84
+ end
85
+
86
+ config_filepath = File.expand_path("~/.mongrel_manager.conf")
87
+
88
+ @config = (File.exists?(config_filepath) and config = YAML.load( File.read(config_filepath) )) ? config : OpenStruct.new(:instances => [])
89
+
90
+ cmd = ARGV.shift
91
+ case cmd
92
+ when 'add'
93
+ cmd_opts = Trollop.options do
94
+ opt :name, "Name of the instance", :type => :string, :required => true
95
+ opt :port, "Port the instance runs on", :type => :int, :required => true
96
+ opt :root, "Root of the project (defaults to CWD)", :type => :string
97
+ end
98
+
99
+ if cmd_opts[:root] == '' or cmd_opts[:root] == nil
100
+ cmd_opts[:root] = Dir.pwd
101
+ end
102
+
103
+ puts "Adding instances #{cmd_opts[:name]} on port #{cmd_opts[:port]} from #{cmd_opts[:root]}"
104
+
105
+ if @config.instances.any? {|i| i.name == cmd_opts[:name] }
106
+ STDERR.puts(" an instance already exists with this name.")
107
+ exit 1
108
+ end
109
+
110
+ if @config.instances.any? {|i| i.port == cmd_opts[:port] }
111
+ STDERR.puts(" an instance already exists with that port.")
112
+ exit 1
113
+ end
114
+
115
+ if @config.instances.any? {|i| i.root == cmd_opts[:root] }
116
+ STDERR.puts(" an instance already exists with that root.")
117
+ exit 1
118
+ end
119
+
120
+ @config.instances << MongrelInstance.new(cmd_opts[:name], cmd_opts[:port], cmd_opts[:root])
121
+
122
+ when 'start', 'stop', 'restart'
123
+ @config.instances.select {|i| ARGV.empty? || ARGV.any? {|n| i.name == n} }.each do |instance|
124
+ if instance.send(cmd)
125
+ puts "#{instance.name} #{cmd}: success"
126
+ else
127
+ puts "#{instance.name} #{cmd}: fail, status: #{instance.status}"
128
+ end
129
+ end
130
+ when 'delete'
131
+ @config.instances.delete_if {|i| ARGV.any? {|n| i.name == n} }
132
+ when 'list', nil, ''
133
+ puts "Managing the following instances:"
134
+ puts ''
135
+ puts Hirb::Helpers::Table.render @config.instances.collect(&:to_hash)
136
+ else
137
+ Trollop::die "Unknown command: #{cmd}"
138
+ end
139
+
140
+ File.open( config_filepath, 'w' ) {|f| YAML.dump(@config, f) }
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongrel-manager
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jon Moses
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-27 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: trollop
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: hirb
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ description: Manage multiple local mongrel instances
45
+ email:
46
+ - jon@burningbush.us
47
+ executables:
48
+ - mongrel-manager
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - README
55
+ has_rdoc: true
56
+ homepage: http://github.com/jmoses/mongrel-manager
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.6
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Manage multiple local mongrel instances
85
+ test_files: []
86
+