Parent

Methods

Included Modules

Class Index [+]

Quicksearch

Ramaze::Bin::Stop

Stops a running instance of Ramaze by killing it’s process. The PID of this process can be supplied via the command line. If no PID is given this command tries to find it in the current directory. If the latter is the case this command tries to find a file of which the name matches the name of the current directory.

Usage:

   ramaze stop
   ramaze stop /home/foobar/projects/ramaze/ramaze.pid

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

Constants

Description

The description of this command, shown when the global help menu is displayed.

Banner

The banner of this command.

Public Class Methods

new() click to toggle source

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

@author Yorick Peterse @since 21-07-2011

    # File lib/ramaze/bin/stop.rb, line 46
46:       def initialize
47:         @options = OptionParser.new do |opt|
48:           opt.banner         = Banner
49:           opt.summary_indent = '  '
50: 
51:           opt.separator "\nOptions:\n"
52: 
53:           opt.on('-h', '--help', 'Shows this help message') do
54:             puts @options
55:             exit
56:           end
57:         end
58:       end

Public Instance Methods

run(argv = []) click to toggle source

Runs the command based on the specified command line arguments.

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

     # File lib/ramaze/bin/stop.rb, line 68
 68:       def run(argv = [])
 69:         @options.parse!(argv)
 70: 
 71:         pid_path = argv.delete_at(0)
 72:         dirname  = Pathname.new('.').expand_path.basename.to_s
 73:         pid_path = File.join(Dir.pwd, dirname + '.pid') if pid_path.nil?
 74: 
 75:         if File.directory?(pid_path)
 76:           pid_path = File.join(pid_path, File.basename(pid_path) + '.pid')
 77:         end
 78: 
 79:         pid_path = Pathname.new(pid_path).expand_path.to_s
 80: 
 81:         if !File.exist?(pid_path)
 82:           abort "The PID #{pid_path} does not exist"
 83:         end
 84: 
 85:         pid = File.read(pid_path).to_i
 86:         puts 'Stopping the process using SIGINT'
 87: 
 88:         begin
 89:           Process.kill('INT', pid)
 90:         rescue => e
 91:           abort "Failed to kill the process: #{e.message}"
 92:         end
 93: 
 94:         sleep(2)
 95: 
 96:         # Verify that the process has been killed
 97:         if is_running?(pid_path)
 98:           $stderr.puts "The process is still running, let's kill it with -9"
 99: 
100:           begin
101:             Process.kill(9, pid)
102:           rescue => e
103:             abort "Failed to kill the process: #{e.message}"
104:           end
105:         end
106: 
107:         File.unlink(pid_path) if File.exist?(pid_path)
108:         puts 'Ramazement has ended, go in peace.'
109:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.