Sha256: 9d166111f9c5b5897847931f53384e6f81329ad818e1b82deecc3be6e11107e3

Contents?: true

Size: 1.82 KB

Versions: 15

Compression:

Stored size: 1.82 KB

Contents

require "active_support"
require "active_support/core_ext"

module FluentdUI
  class Command < Thor
    ROOT = File.expand_path('../../../', __FILE__)


    desc "start", "start fluentd-ui server"
    option :port, type: :numeric, default: 9292
    option :pidfile, type: :string, default: File.expand_path('tmp/fluentd-ui.pid', ROOT)
    option :daemonize, type: :boolean, default: false
    def start
      trap(:INT) { puts "\nStopping..." }
      # NOTE: on Debian based distributions, td-agent uses start-stop-daemon with --exec option for stopping process
      #       then fluentd-ui will be killed by them because given --exec option matches.
      #       FLUENTD_UI_EXEC_COMMAND is used for workaround it.
      cmd = ENV['FLUENTD_UI_EXEC_COMMAND'].presence || "rackup"
      system(* %w(bundle exec) + cmd.split(" ") + %W(#{options[:daemonize] ? "-D" : ""} --pid #{options[:pidfile]} -p #{options[:port]} -E production #{ROOT}/config.ru))
    end


    desc "stop", "stop fluentd-ui server"
    option :pidfile, type: :string, default: File.expand_path('tmp/fluentd-ui.pid', ROOT)
    def stop
      Process.kill(:TERM, pid) if pid
    rescue Errno::ESRCH
    ensure
      puts "stopped"
    end


    desc "status", "status of fluentd-ui server"
    option :pidfile, type: :string, default: File.expand_path('tmp/fluentd-ui.pid', ROOT)
    def status
      if pid && Process.kill(0, pid)
        puts "fluentd-ui is running"
      else
        puts "fluentd-ui is stopped"
      end
    rescue Errno::ESRCH
      puts "fluentd-ui is stopped"
    end


    desc "setup", "setup fluentd-ui server"
    long_desc <<-DESC
      install dependency gems
    DESC
    def setup
      trap(:INT) { puts "\nStopping..." }
      system(*%W(bundle install))
    end

    private

    def pid
      File.read(options[:pidfile]).to_i rescue nil
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
fluentd-ui-0.3.19 lib/fluentd-ui/command.rb
fluentd-ui-0.3.18 lib/fluentd-ui/command.rb
fluentd-ui-0.3.17 lib/fluentd-ui/command.rb
fluentd-ui-0.3.16 lib/fluentd-ui/command.rb
fluentd-ui-0.3.15 lib/fluentd-ui/command.rb
fluentd-ui-0.3.14 lib/fluentd-ui/command.rb
fluentd-ui-0.3.13 lib/fluentd-ui/command.rb
fluentd-ui-0.3.12 lib/fluentd-ui/command.rb
fluentd-ui-0.3.11 lib/fluentd-ui/command.rb
fluentd-ui-0.3.10 lib/fluentd-ui/command.rb
fluentd-ui-0.3.9 lib/fluentd-ui/command.rb
fluentd-ui-0.3.8 lib/fluentd-ui/command.rb
fluentd-ui-0.3.7 lib/fluentd-ui/command.rb
fluentd-ui-0.3.6 lib/fluentd-ui/command.rb
fluentd-ui-0.3.5 lib/fluentd-ui/command.rb