From 255b8257e9c4fc334071fb1f5414fd122e93006a Mon Sep 17 00:00:00 2001 From: uu59 Date: Tue, 3 Jun 2014 16:39:56 +0900 Subject: [PATCH 1/2] Add subcommands to bin/fluentd-ui --- Gemfile.lock | 1 + README.md | 12 +++++--- bin/fluentd-ui | 8 ++++-- fluentd-ui.gemspec | 1 + lib/fluentd-ui/command.rb | 60 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 lib/fluentd-ui/command.rb diff --git a/Gemfile.lock b/Gemfile.lock index 70d08b0..ba14444 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,6 +18,7 @@ PATH settingslogic sqlite3 sucker_punch (~> 1.0.5) + thor GEM remote: https://rubygems.org/ diff --git a/README.md b/README.md index 477aac5..074b102 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,14 @@ fluentd-ui is a browser-based [fluentd](http://fluentd.org/) and [td-agent](http # Getting Started - $ gem install fluentd-ui - $ fluentd-ui - # Open http://localhost:9292/ by your browser - # default account is username="admin" and password="changeme" +```console +$ gem install fluentd-ui +$ fluentd-ui setup +create DB, create initial user, etc. +$ fluentd-ui start +Open http://localhost:9292/ by your browser +default account is username="admin" and password="changeme" +``` Or, for developers. diff --git a/bin/fluentd-ui b/bin/fluentd-ui index 465c6ea..8f90c09 100755 --- a/bin/fluentd-ui +++ b/bin/fluentd-ui @@ -1,11 +1,13 @@ #!/usr/bin/env ruby require "securerandom" +require "thor" dir = File.expand_path("../../", __FILE__) ENV["BUNDLE_GEMFILE"] ||= File.join(dir, "Gemfile.production") ENV["SECRET_KEY_BASE"] ||= SecureRandom.hex(64) ENV["RAILS_ENV"] ||= "production" -system(*%W(bundle install)) -system(*%W(bundle exec rake db:create db:migrate db:seed)) -system(*%W(bundle exec rackup -E production #{dir}/config.ru)) + +require File.join(dir, "lib/fluentd-ui/command.rb") + +FluentdUI::Command.start(ARGV) diff --git a/fluentd-ui.gemspec b/fluentd-ui.gemspec index 3666793..995053e 100644 --- a/fluentd-ui.gemspec +++ b/fluentd-ui.gemspec @@ -34,4 +34,5 @@ Gem::Specification.new do |spec| spec.add_dependency "httpclient" spec.add_dependency "settingslogic" spec.add_dependency "puma" + spec.add_dependency "thor" end diff --git a/lib/fluentd-ui/command.rb b/lib/fluentd-ui/command.rb new file mode 100644 index 0000000..7523ee4 --- /dev/null +++ b/lib/fluentd-ui/command.rb @@ -0,0 +1,60 @@ +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 + # NOTE: When fluentd-ui gem updated, it may have new migrations. + # do `setup` before `start` solve that, but currently don't. should decide later. + # setup + system(*%W(bundle exec rackup #{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 + 1. install dependency gems + + 2. create DB + + 3. create initial user if no user registered + DESC + def setup + system(*%W(bundle install)) + system(*%W(bundle exec rake db:create db:migrate db:seed)) + end + + private + + def pid + File.read(options[:pidfile]).to_i rescue nil + end + end +end From 317a9158aea10f1b74c36fac1fbcbf6055c9f3dc Mon Sep 17 00:00:00 2001 From: uu59 Date: Tue, 3 Jun 2014 16:48:32 +0900 Subject: [PATCH 2/2] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 074b102..12fb3e1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # fluentd-ui -fluentd-ui is a browser-based [fluentd](http://fluentd.org/) and [td-agent](http://docs.treasuredata.com/articles/td-agent) manager than can following operations. +fluentd-ui is a browser-based [fluentd](http://fluentd.org/) and [td-agent](http://docs.treasuredata.com/articles/td-agent) manager that can following operations. * Install, uninstall, and upgrade fluentd plugins * start/stop/restart fluentd process