module Cluster
  class SerialRestart < GemPlugin::Plugin "/commands"
    include Cluster::ExecBase

    def configure
      options [
        ['-C', '--config PATH', "Path to cluster configuration file", :@config_file, "config/mongrel_cluster.yml"],
        ['-v', '--verbose', "Print all called commands and output.", :@verbose, false],
        ['', '--only PORT', "Port number of cluster member", :@only, nil]
      ]
    end

    def run
      read_options

      @ports.each do |p|
        @only = p
        @force = false
        @clean = true

        stop

        if check_process(p)
          log "sleeping for a little bit before force kill"
          sleep 10
          @force = true
          stop
        end

        start

      end
    end
  end
end
