# File src/PlugMan.rb, line 477
    def PlugMan.stop_plugin(name)
      plug = @registered_plugins[name]

      required_by(name).each do |nm|
        stop_plugin(nm)
      end
    
      if plug && plug.state == :started || plug.state == :error
        @logger.debug { "Stopping plugin #{plug.name.inspect}" }

        if plug.stop
          plug.state :stopped
          changed
          notify_observers(:stopped, plug)
        else
          plug.state :error
          @logger.error { "Failed to stop plugin #{name.inspect}" }
          changed
          notify_observers(:error, plug)
          raise PluginError.new(:stop_failed)
        end
      end
    end