mrd 0.0.2 → 0.0.3

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/bin/mrd +45 -22
  2. data/lib/mrd/version.rb +1 -1
  3. metadata +3 -3
data/bin/mrd CHANGED
@@ -90,6 +90,7 @@ class App
90
90
  mounts = run!("mount")
91
91
  mounts =~ /#{@device} on (.*) \(/
92
92
  $1 or raise RuntimeError.new("Cannot determine mountpoint")
93
+ $1 != '/' or raise RuntimeError.new("Bad mountpoint '#{$1}' for #{@device}")
93
94
  Pathname.new($1)
94
95
  end
95
96
  end
@@ -109,53 +110,54 @@ class App
109
110
 
110
111
  def initialize(ramdisk)
111
112
  @ramdisk = ramdisk
112
- @socket = @ramdisk.mountpoint.join('mysql.sock')
113
- @pidfile = @ramdisk.mountpoint.join('mysql.pid')
114
- @config = @ramdisk.mountpoint.join('my.cnf')
115
-
116
113
  @install_db = find_command! %w(mysql_install_db5 mysql_install_db)
117
114
  @mysqld = find_command! %w(mysqld_safe5 mysqld_safe)
118
115
  end
119
116
 
120
117
  def start
121
118
  # Setup config
122
- File.open(@config, 'w') do |fd|
119
+ File.open(configfile, 'w') do |fd|
123
120
  fd.write %Q{
124
121
  [client]
125
- socket = #{@socket}
122
+ socket = #{socket}
126
123
  [mysqld]
127
- socket = #{@socket}
124
+ socket = #{socket}
128
125
  thread_concurrency = 4
129
- # innodb_data_home_dir =
130
126
  innodb_data_file_path = ibdata1:10M:autoextend
131
- #innodb_log_group_home_dir = /opt/local/var/db/mysql5
132
127
  innodb_file_per_table
133
128
  ft_min_word_len = 3
134
129
  }.gsub(/^\s+/,'')
135
130
  end
136
131
 
132
+ # Switch to the MySQL install directory (on some platforms the install script uses relative paths)
133
+ Dir.chdir @install_db.parent.parent
134
+
137
135
  # Setup base databases
138
136
  run!("#{@install_db} --datadir='#{@ramdisk.mountpoint}'")
139
137
 
140
138
  # Start server in another thread
141
139
  Logger.info 'Starting MySQL server'
142
140
  @thread = Thread.new do
143
- run!("#{@mysqld} --defaults-file='#{@config}' --socket='#{@socket}' --datadir='#{@ramdisk.mountpoint}' --pid-file='#{@pidfile}' --skip-networking")
141
+ run!("#{@mysqld} --defaults-file='#{configfile}' --socket='#{socket}' --datadir='#{@ramdisk.mountpoint}' --pid-file='#{pidfile}' --skip-networking")
144
142
  end
145
143
 
146
144
  # Wait for PID file
147
- wait_for { Logger.debug "Waiting for PID file..." ; @pidfile.exist? }
145
+ wait_for { Logger.debug "Waiting for PID file..." ; pidfile.exist? }
148
146
  self
149
147
  end
150
148
 
151
149
  def stop
152
- return unless @pidfile
150
+ return unless pidfile && pidfile.exist?
153
151
  # Terminate server
154
152
  Logger.info "Stopping server..."
155
- pid = @pidfile.read.to_i
153
+ pid = pidfile.read.to_i
156
154
  Process.kill("TERM", pid)
157
155
  Logger.debug "Killed server process (#{pid})."
158
- wait_for { Logger.debug "Waiting for PID file..." ; !@pidfile.exist? }
156
+ wait_for { Logger.debug "Waiting for PID file..." ; !pidfile.exist? }
157
+ end
158
+
159
+ def socket
160
+ @ramdisk && @ramdisk.mountpoint.join('mysql.sock')
159
161
  end
160
162
 
161
163
  private
@@ -173,11 +175,21 @@ class App
173
175
  def find_command!(variants)
174
176
  variants.each do |variant|
175
177
  path = run("which #{variant}")
176
- return path unless path.empty?
178
+ return Pathname.new(path) unless path.empty?
177
179
  end
178
180
  Logger.error "Sorry, I need one of #{variants.join ', '} to run."
179
181
  Kernel.exit
180
182
  end
183
+
184
+ def pidfile
185
+ @ramdisk && @ramdisk.mountpoint.join('mysql.pid')
186
+ end
187
+
188
+ def configfile
189
+ @ramdisk && @ramdisk.mountpoint.join('my.cnf')
190
+ end
191
+
192
+
181
193
  end
182
194
 
183
195
 
@@ -192,9 +204,17 @@ class App
192
204
 
193
205
 
194
206
  def main
207
+ @ramdisk = Ramdisk.new(options.size)
208
+ @server = MySQLServer.new(@ramdisk)
209
+ rd,wr = IO.pipe
210
+
195
211
  if pid = Process.fork
212
+ wr.close
213
+ @pipe = rd
196
214
  parent_main(pid)
197
215
  else
216
+ rd.close
217
+ @pipe = wr
198
218
  child_main
199
219
  end
200
220
  end
@@ -204,13 +224,15 @@ class App
204
224
  Process.detach(child_pid)
205
225
  wait_forever
206
226
  rescue Interrupt
207
- Kernel.exit
227
+ # Kernel.exit
228
+ Logger.debug 'Waiting for child to complete...'
229
+ @pipe.gets
208
230
  end
209
231
 
210
232
  def child_main
211
233
  # Logger.info 'in child'
212
- @ramdisk = Ramdisk.new(options.size).mount
213
- @server = MySQLServer.new(@ramdisk).start
234
+ @ramdisk.mount
235
+ @server.start
214
236
  Signal.trap("HUP") do
215
237
  Logger.warn "SIGHUP received"
216
238
  cleanup
@@ -228,16 +250,17 @@ class App
228
250
  cleanup
229
251
  end
230
252
 
253
+ private
254
+
255
+
256
+ attr :options
257
+
231
258
  def cleanup
232
259
  @server.stop if @server
233
260
  @ramdisk.unmount if @ramdisk
234
261
  end
235
262
 
236
263
 
237
- private
238
-
239
- attr :options
240
-
241
264
  def option_parser
242
265
  OptionParser.new do |opts|
243
266
  opts.banner = "Usage: #{$progname} [options]"
data/lib/mrd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mrd
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mrd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  segments:
78
78
  - 0
79
- hash: -301293182329990722
79
+ hash: -1819939860976838345
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: -301293182329990722
88
+ hash: -1819939860976838345
89
89
  requirements: []
90
90
  rubyforge_project:
91
91
  rubygems_version: 1.8.23