Sha256: a28485d316b18610f2d10af51c1523a1fa9d04f90b989e3f308d9dbd4fbd9587

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

module Flydata
  module Command
    class Sender < Base
      FLYDATA_HOME=Flydata::HOME_DIR
      def start
        if process_exist?
          say("Process exist. Please stop process first.")
          return
        end

        retry_count = 10
        1.upto(retry_count) do |i|
          break if server_ready?
          say("Waiting server side active... (#{i}/#{retry_count})")
          sleep 30
        end

        say('Starting sender process.')
        system("fluentd -d #{FLYDATA_HOME}/flydata.pid -l #{FLYDATA_HOME}/flydata.log -c #{FLYDATA_HOME}/flydata.conf")

        sleep 5
        retry_count = 10
        1.upto(retry_count) do |i|
          if client_ready?
            say('Done.')
            return true
          end
          say("Waiting client side active... (#{i}/#{retry_count})")
          sleep 30
        end

        say('Something wrong..')
      end
      def stop
        say('Stopping sender process.')
        if system("kill `cat #{FLYDATA_HOME}/flydata.pid`")
          say('Done.')
          return true
        else
          say('Something wrong..')
        end
      end
      def restart
        say('Restarting sender process.')
        stop and start
      end

      private
      def server_ready?
        data_port = flydata.data_port.get
        data_port['server_status'] == 'active'
      end
      def client_ready?
        process_exist?
      end
      def process_exist?
        process_count = `ps aux|grep -v grep|grep "\\.flydata/flydata\\.conf"|grep fluentd|wc -l`.to_i
        process_count > 0
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flydata-0.0.1.2011102401 lib/flydata/command/sender.rb
flydata-0.0.1.2011102303 lib/flydata/command/sender.rb