test/support/apache2_controller.rb
def stop
    pid_file = "#{@server_root}/httpd.pid"
    if File.exist?(pid_file)
      begin
        pid = File.read(pid_file).strip.to_i
        Process.kill('SIGTERM', pid)
      rescue Errno::ESRCH
        # Looks like a stale pid file.
        FileUtils.rm_r(@server_root)
        return
      end
    end
    begin
      # Wait until the PID file is removed.
      Timeout::timeout(17) do
        while File.exist?(pid_file)
          sleep(0.1)
        end
      end
      # Wait until the server socket is closed.
      Timeout::timeout(7) do
        done = false
        while !done
          begin
            socket = TCPSocket.new('localhost', @port)
            socket.close
            sleep(0.1)
          rescue SystemCallError
            done = true
          end
        end
      end
    rescue Timeout::Error
      raise "Unable to stop Apache."
    end
    if File.exist?(@server_root)
      FileUtils.chmod_R(0777, @server_root)
      FileUtils.rm_r(@server_root)
    end
  end
# Stop Apache and delete its configuration folder. This method waits
# until Apache is done with its shutdown procedure.
#
# This method does nothing if Apache is already stopped.
Stop Apache and delete its configuration folder. This method waits
until Apache is done with its shutdown procedure.

This method does nothing if Apache is already stopped.
Stop Apache and delete its configuration folder . This method waits until Apache is done with its shutdown procedure . This method does nothing if Apache is already stopped .
def stop
    pid_file = "#{@server_root}/httpd.pid"
    if File.exist?(pid_file)
      begin
        pid = File.read(pid_file).strip.to_i
        Process.kill('SIGTERM', pid)
      rescue Errno::ESRCH
        FileUtils.rm_r(@server_root)
        return
      end
    end
    begin
      Timeout::timeout(17) do
        while File.exist?(pid_file)
          sleep(0.1)
        end
      end
      Timeout::timeout(7) do
        done = false
        while !done
          begin
            socket = TCPSocket.new('localhost', @port)
            socket.close
            sleep(0.1)
          rescue SystemCallError
            done = true
          end
        end
      end
    rescue Timeout::Error
      raise "Unable to stop Apache."
    end
    if File.exist?(@server_root)
      FileUtils.chmod_R(0777, @server_root)
      FileUtils.rm_r(@server_root)
    end
  end
def stop pid_file = "#{@server_root}/httpd.pid" if File . exist? ( pid_file ) begin pid = File . read ( pid_file ) . strip . to_i Process . kill ( 'SIGTERM' , pid ) rescue Errno :: ESRCH FileUtils . rm_r ( @server_root ) return end end begin Timeout :: timeout ( 17 ) do while File . exist? ( pid_file ) sleep ( 0.1 ) end end Timeout :: timeout ( 7 ) do done = false while ! done begin socket = TCPSocket . new ( 'localhost' , @port ) socket . close sleep ( 0.1 ) rescue SystemCallError done = true end end end rescue Timeout :: Error raise "Unable to stop Apache." end if File . exist? ( @server_root ) FileUtils . chmod_R ( 0777 , @server_root ) FileUtils . rm_r ( @server_root ) end end
Stop Apache and delete its configuration folder.
Stop Apache and delete its configuration folder .
# Looks like a stale pid file. # Wait until the PID file is removed. # Wait until the server socket is closed.