# File lib/mongrel_cluster/init.rb, line 186 186: def chdir_cwd 187: pwd = Dir.pwd 188: Dir.chdir(@options["cwd"]) if @options["cwd"] 189: yield 190: Dir.chdir(pwd) if @options["cwd"] 191: end
# File lib/mongrel_cluster/init.rb, line 167 167: def check_process(port) 168: if pid_file_exists?(port) 169: pid = read_pid(port) 170: ps_output = `ps -o #{cmd_name}= -p #{pid}` 171: pid = ps_output =~ /mongrel_rails/ ? pid : nil 172: else 173: pid = find_pid(port) 174: end 175: pid 176: end
# File lib/mongrel_cluster/init.rb, line 182 182: def cmd_flags 183: RUBY_PLATFORM =~ /solaris|aix/ ? "-eo" : "-ewwo" 184: end
# File lib/mongrel_cluster/init.rb, line 178 178: def cmd_name 179: RUBY_PLATFORM =~ /solaris|aix/ ? "args" : "command" 180: end
# File lib/mongrel_cluster/init.rb, line 202 202: def find_pid(port) 203: ps_cmd = "ps #{cmd_flags} pid,#{cmd_name}" 204: ps_output = `#{ps_cmd}` 205: ps_output.each do |line| 206: if line =~ /-P #{Regexp.escape(port_pid_file(port))} / 207: pid = line.split[0] 208: return pid 209: end 210: end 211: nil 212: end
# File lib/mongrel_cluster/init.rb, line 222 222: def log(message) 223: puts message 224: end
# File lib/mongrel_cluster/init.rb, line 214 214: def log_error(message) 215: log(message) 216: end
# File lib/mongrel_cluster/init.rb, line 218 218: def log_verbose(message) 219: log(message) if @verbose 220: end
# File lib/mongrel_cluster/init.rb, line 158 158: def pid_file_exists?(port) 159: pid_file = port_pid_file(port) 160: exists = false 161: chdir_cwd do 162: exists = File.exists?(pid_file) 163: end 164: exists 165: end
# File lib/mongrel_cluster/init.rb, line 54 54: def port_log_file(port) 55: log_file = [@log_file_base, port].join(".") + @log_file_ext 56: File.join(@log_file_dir, log_file) 57: end
# File lib/mongrel_cluster/init.rb, line 49 49: def port_pid_file(port) 50: pid_file = [@pid_file_base, port].join(".") + @pid_file_ext 51: File.join(@pid_file_dir, pid_file) 52: end
# File lib/mongrel_cluster/init.rb, line 43 43: def process_log_file(log_file) 44: @log_file_ext = File.extname(log_file) 45: @log_file_base = File.basename(log_file, @log_file_ext) 46: @log_file_dir = File.dirname(log_file) 47: end
# File lib/mongrel_cluster/init.rb, line 37 37: def process_pid_file(pid_file) 38: @pid_file_ext = File.extname(pid_file) 39: @pid_file_base = File.basename(pid_file, @pid_file_ext) 40: @pid_file_dir = File.dirname(pid_file) 41: end
# File lib/mongrel_cluster/init.rb, line 17 17: def read_options 18: @options = { 19: "environment" => ENV['RAILS_ENV'] || "development", 20: "port" => 3000, 21: "pid_file" => "tmp/pids/mongrel.pid", 22: "log_file" => "log/mongrel.log", 23: "servers" => 2 24: } 25: conf = YAML.load_file(@config_file) 26: @options.merge! conf if conf 27: 28: process_pid_file @options["pid_file"] 29: process_log_file @options["log_file"] 30: 31: start_port = end_port = @only 32: start_port ||= @options["port"].to_i 33: end_port ||= start_port + @options["servers"] - 1 34: @ports = (start_port..end_port).to_a 35: end
# File lib/mongrel_cluster/init.rb, line 193 193: def read_pid(port) 194: pid_file = port_pid_file(port) 195: pid = 0 196: chdir_cwd do 197: pid = File.read(pid_file) 198: end 199: pid 200: end
# File lib/mongrel_cluster/init.rb, line 59 59: def start 60: read_options 61: 62: argv = [ "mongrel_rails" ] 63: argv << "start" 64: argv << "-d" 65: argv << "-e #{@options['environment']}" if @options['environment'] 66: argv << "-a #{@options['address']}" if @options['address'] 67: argv << "-c #{@options['cwd']}" if @options['cwd'] 68: argv << "-o #{@options['timeout']}" if @options['timeout'] 69: argv << "-t #{@options['throttle']}" if @options['throttle'] 70: argv << "-m #{@options['mime_map']}" if @options['mime_map'] 71: argv << "-r #{@options['docroot']}" if @options['docroot'] 72: argv << "-n #{@options['num_procs']}" if @options['num_procs'] 73: argv << "-B" if @options['debug'] 74: argv << "-S #{@options['config_script']}" if @options['config_script'] 75: argv << "--user #{@options['user']}" if @options['user'] 76: argv << "--group #{@options['group']}" if @options['group'] 77: argv << "--prefix #{@options['prefix']}" if @options['prefix'] 78: cmd = argv.join " " 79: 80: @ports.each do |port| 81: if @clean && pid_file_exists?(port) && !check_process(port) 82: pid_file = port_pid_file(port) 83: log "missing process: removing #{pid_file}" 84: chdir_cwd do 85: File.unlink(pid_file) 86: end 87: end 88: 89: if pid_file_exists?(port) && check_process(port) 90: log "already started port #{port}" 91: next 92: end 93: 94: exec_cmd = cmd + " -p #{port} -P #{port_pid_file(port)}" 95: exec_cmd += " -l #{port_log_file(port)}" 96: log "starting port #{port}" 97: log_verbose exec_cmd 98: output = `#{exec_cmd}` 99: log_error output unless $?.success? 100: end 101: end
# File lib/mongrel_cluster/init.rb, line 133 133: def status 134: read_options 135: 136: status = STATUS_OK 137: 138: @ports.each do |port| 139: pid = check_process(port) 140: unless pid_file_exists?(port) 141: log "missing pid_file: #{port_pid_file(port)}" 142: status = STATUS_ERROR 143: else 144: log "found pid_file: #{port_pid_file(port)}" 145: end 146: if pid 147: log "found mongrel_rails: port #{port}, pid #{pid}" 148: else 149: log "missing mongrel_rails: port #{port}" 150: status = STATUS_ERROR 151: end 152: puts "" 153: end 154: 155: status 156: end
# File lib/mongrel_cluster/init.rb, line 103 103: def stop 104: read_options 105: 106: argv = [ "mongrel_rails" ] 107: argv << "stop" 108: argv << "-c #{@options["cwd"]}" if @options["cwd"] 109: argv << "-f" if @force 110: cmd = argv.join " " 111: 112: @ports.each do |port| 113: pid = check_process(port) 114: if @clean && pid && !pid_file_exists?(port) 115: log "missing pid_file: killing mongrel_rails port #{port}, pid #{pid}" 116: Process.kill("KILL", pid.to_i) 117: end 118: 119: if !check_process(port) 120: log "already stopped port #{port}" 121: next 122: end 123: 124: exec_cmd = cmd + " -P #{port_pid_file(port)}" 125: log "stopping port #{port}" 126: log_verbose exec_cmd 127: output = `#{exec_cmd}` 128: log_error output unless $?.success? 129: 130: end 131: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.