# File lib/daemons/application.rb, line 379
    def stop(no_wait = false)
      if not running?
        self.zap
        return
      end
      
      pid = @pid.pid
      
      # Catch errors when trying to kill a process that doesn't
      # exist. This happens when the process quits and hasn't been
      # restarted by the monitor yet. By catching the error, we allow the
      # pid file clean-up to occur.
      begin
        Process.kill(SIGNAL, pid)
      rescue Errno::ESRCH => e
        puts "#{e} #{pid}"
        puts "deleting pid-file."
      end
      
      if not no_wait
        if @force_kill_waittime > 0
          puts "#{self.group.app_name}: trying to stop process with pid #{pid}..."
          STDOUT.flush
          
          begin
            Timeout::timeout(@force_kill_waittime) {
              while Pid.running?(pid)
                sleep(0.2)
              end
            }
          rescue Timeout::Error
            puts "#{self.group.app_name}: process with pid #{pid} won't stop, we forcefully kill it..."
            STDOUT.flush
            
            begin
              Process.kill('KILL', pid)
            rescue Errno::ESRCH
            end
            
            begin
              Timeout::timeout(20) {
                while Pid.running?(pid)
                  sleep(1)
                end
              }
            rescue Timeout::Error
              puts "#{self.group.app_name}: unable to forcefully kill process with pid #{pid}."
              STDOUT.flush
            end
          end
        end
        
        
      end
      
      sleep(0.1)
      unless Pid.running?(pid)
        # We try to remove the pid-files by ourselves, in case the application
        # didn't clean it up.
        begin; @pid.cleanup; rescue ::Exception; end
        
        puts "#{self.group.app_name}: process with pid #{pid} successfully stopped."
        STDOUT.flush
      end
      
    end