Parent

Methods

Included Modules

Class Index [+]

Quicksearch

Ramaze::Bin::Status

The status command can be used to show the details, such as the PID and the CPU usage, of a running Ramaze application.

Usage:

   ramaze status
   ramaze status /home/projects/ramaze/ramaze.pid

@author Yorick Peterse @author TJ Vanderpoel @since 21-07-2011

Constants

Description

Description of this command, displayed in the glboal help message.

Banner

The banner of this command, displayed when the -h or —help option is specified.

Statistics

String containing the message that’s used to display all statistics

Public Class Methods

new() click to toggle source

Creates a new instance of the command and sets all the option parser options.

@author Yorick Peterse @since 21-07-2011

    # File lib/ramaze/bin/status.rb, line 55
55:       def initialize
56:         @options = OptionParser.new do |opt|
57:           opt.banner         = Banner
58:           opt.summary_indent = '  '
59: 
60:           opt.separator "\nOptions:\n"
61: 
62:           opt.on('-h', '--help', 'Shows this help message') do
63:             puts @options
64:             exit
65:           end
66:         end
67:       end

Public Instance Methods

run(argv = []) click to toggle source

Runs the command based on the given command line arguments.

@author Yorick Peterse @author TJ Vanderpoel @since 21-07-2011 @param [Array] argv Array containing all teh command line arguments.

     # File lib/ramaze/bin/status.rb, line 77
 77:       def run(argv = [])
 78:         @options.parse!(argv)
 79: 
 80:         pid_path = argv.delete_at(0)
 81:         dirname  = Pathname.new('.').realpath.basename.to_s
 82:         pid_path = File.join(Dir.pwd, dirname + '.pid') if pid_path.nil?
 83: 
 84:         # Is it a directory?
 85:         if File.directory?(pid_path)
 86:           pid_path = File.join(pid_path, File.basename(pid_path) + '.pid')
 87:         end
 88: 
 89:         pid_path = Pathname.new(pid_path).expand_path.to_s
 90: 
 91:         if !File.exist?(pid_path)
 92:           abort "The PID #{pid_path} does not exist"
 93:         end
 94: 
 95:         # Is the app running?
 96:         unless is_running?(pid_path)
 97:           abort "The Ramaze application for #{pid_path} isn't running"
 98:         end
 99: 
100:         pid = File.read(pid_path).to_i
101: 
102:         # Gather various statistics about the process
103:         if is_windows?
104:           wmi       = WIN32OLE.connect("winmgmts://")
105:           ours      = []
106:           processes = wmi.ExecQuery(
107:             "select * from win32_process where ProcessId = #{pid}"
108:           )
109: 
110:           processes.each do |p|
111:             ours << [
112:               p.Name,
113:               p.CommandLine,
114:               p.VirtualSize,
115:               p.CreationDate,
116:               p.ExecutablePath,
117:               p.Status
118:             ]
119:           end
120: 
121:           puts Statistics % ours.first
122:         # Unix like systems
123:         else
124:           if File.directory?(proc_dir = Pathname.new('/proc'))
125:             proc_dir = proc_dir.join(pid.to_s)
126:             # If we have a "stat" file, we'll assume linux and get as much info
127:             # as we can
128:             if File.file?(stat_file = proc_dir.join("stat"))
129:               stats = File.read(stat_file).split
130: 
131:               puts Statistics % [
132:                 nil,
133:                 File.read(proc_dir.join("cmdline")).split("\0000").join(" "),
134:                 "%s k" % (stats[22].to_f / 1024),
135:                 File.mtime(proc_dir),
136:                 File.readlink(proc_dir.join("exe")),
137:                 stats[2]
138:               ]
139:             end
140:           # /proc does not exist, use "ps"
141:           else
142:             begin
143:               puts %{ps l #{pid}}
144:             rescue
145:               puts "Sadly no more information is available"
146:             end
147:           end
148:         end
149:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.