mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-14 18:27:06 +02:00
commit
959c2b2bc1
@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base
|
|||||||
helper_method :fluentd_exists?
|
helper_method :fluentd_exists?
|
||||||
before_action :login_required
|
before_action :login_required
|
||||||
before_action :set_locale
|
before_action :set_locale
|
||||||
|
before_action :notice_new_fluentd_ui_available
|
||||||
|
|
||||||
def current_user
|
def current_user
|
||||||
return unless session[:succeed_password]
|
return unless session[:succeed_password]
|
||||||
@ -50,6 +51,12 @@ class ApplicationController < ActionController::Base
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def notice_new_fluentd_ui_available
|
||||||
|
if FluentdUI.update_available?
|
||||||
|
flash[:info] = I18n.t("messages.available_new_fluentd_ui", version: FluentdUI.latest_version, update_url: misc_information_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def find_fluentd
|
def find_fluentd
|
||||||
@fluentd = Fluentd.instance
|
@fluentd = Fluentd.instance
|
||||||
end
|
end
|
||||||
|
@ -9,4 +9,24 @@ class MiscController < ApplicationController
|
|||||||
@env = ENV
|
@env = ENV
|
||||||
@plugins = Plugin.installed
|
@plugins = Plugin.installed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_fluentd_ui
|
||||||
|
FluentdUiRestart.new.async.perform
|
||||||
|
@current_pid = $$
|
||||||
|
render "update_fluentd_ui", layout: "sign_in"
|
||||||
|
end
|
||||||
|
|
||||||
|
def upgrading_status
|
||||||
|
if FluentdUiRestart::LOCK.present?
|
||||||
|
return render text: "updating"
|
||||||
|
end
|
||||||
|
|
||||||
|
if $$.to_s == params[:old_pid]
|
||||||
|
# restarting fluentd-ui is finished, but PID doesn't changed.
|
||||||
|
# maybe error occured at FluentdUiRestart#perform
|
||||||
|
render text: "failed"
|
||||||
|
else
|
||||||
|
render text: "finished"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,6 +22,8 @@ class Plugin
|
|||||||
|
|
||||||
self.version ||= latest_version
|
self.version ||= latest_version
|
||||||
if valid? && gem_install
|
if valid? && gem_install
|
||||||
|
# NOTE: also updating fluentd-ui gem is used this method, that shouldn't be recorded
|
||||||
|
return true unless gem_name.start_with?("fluent-plugin-")
|
||||||
File.open(gemfile_path, "a") do |f|
|
File.open(gemfile_path, "a") do |f|
|
||||||
f.puts format_gemfile
|
f.puts format_gemfile
|
||||||
end
|
end
|
||||||
|
@ -18,14 +18,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4 col-md-offset-4">
|
<div class="col-md-4 col-md-offset-4">
|
||||||
<div class="login-panel panel panel-default">
|
<%= yield %>
|
||||||
<div class="panel-heading">
|
|
||||||
<h3 class="panel-title"><%= t('messages.please_sign_in') %></h3>
|
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
<%= yield %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,55 +1,64 @@
|
|||||||
- page_title t('.page_title')
|
- page_title t('.page_title')
|
||||||
|
|
||||||
%div.col-lg-6
|
- if FluentdUI.update_available?
|
||||||
%div.panel.panel-info
|
.row
|
||||||
%div.panel-heading
|
.col-lg-12
|
||||||
%h4= t ".version"
|
%p
|
||||||
%div.panel-body
|
= link_to misc_update_fluentd_ui_path, class: "btn btn-primary btn-lg", method: :post do
|
||||||
%dl{class: "dl-horizontal"}
|
= t('.update_fluentd_ui', version: FluentdUI.latest_version)
|
||||||
%dt ruby
|
= t('.update_fluentd_ui_caution')
|
||||||
%dd= RUBY_DESCRIPTION
|
|
||||||
%dt fluentd
|
|
||||||
%dd= Fluent::VERSION
|
|
||||||
%dt fluentd-ui
|
|
||||||
%dd= FluentdUI::VERSION
|
|
||||||
|
|
||||||
|
.row
|
||||||
|
%div.col-lg-6
|
||||||
|
%div.panel.panel-default
|
||||||
|
%div.panel-heading
|
||||||
|
%h4= t ".version"
|
||||||
|
%div.panel-body
|
||||||
|
%dl{class: "dl-horizontal"}
|
||||||
|
%dt ruby
|
||||||
|
%dd= RUBY_DESCRIPTION
|
||||||
|
%dt fluentd
|
||||||
|
%dd= Fluent::VERSION
|
||||||
|
%dt fluentd-ui
|
||||||
|
%dd= FluentdUI::VERSION
|
||||||
|
|
||||||
%div.col-lg-6
|
%div.col-lg-6
|
||||||
%div.panel.panel-default
|
%div.panel.panel-default
|
||||||
%div.panel-heading
|
%div.panel-heading
|
||||||
%h4= t('.installed_plugins')
|
%h4= t('.installed_plugins')
|
||||||
%div.panel-body
|
%div.panel-body
|
||||||
- if @plugins.present?
|
- if @plugins.present?
|
||||||
%table{class: "table table-hover", id: "plugins-table"}
|
%table{class: "table table-hover", id: "plugins-table"}
|
||||||
%thead
|
%thead
|
||||||
%tr
|
|
||||||
%th= t('plugins.common.name')
|
|
||||||
%th= t('plugins.common.version')
|
|
||||||
%tbody
|
|
||||||
- @plugins.each do |plugin|
|
|
||||||
%tr
|
%tr
|
||||||
%td= plugin.gem_name
|
%th= t('plugins.common.name')
|
||||||
%td= plugin.installed_version
|
%th= t('plugins.common.version')
|
||||||
- else
|
%tbody
|
||||||
= t "plugins.common.no_installed"
|
- @plugins.each do |plugin|
|
||||||
|
%tr
|
||||||
|
%td= plugin.gem_name
|
||||||
|
%td= plugin.installed_version
|
||||||
|
- else
|
||||||
|
= t "plugins.common.no_installed"
|
||||||
|
|
||||||
%div.col-lg-12
|
.row
|
||||||
%div.panel.panel-default
|
%div.col-lg-12
|
||||||
%div.panel-heading
|
%div.panel.panel-default
|
||||||
%h4
|
%div.panel-heading
|
||||||
%a{"data-toggle" => "collapse", "href" => "#env-table"}
|
%h4
|
||||||
= icon('fa-caret-down')
|
%a{"data-toggle" => "collapse", "href" => "#env-table"}
|
||||||
= t('.env')
|
= icon('fa-caret-down')
|
||||||
%table{class: "table table-hover collapse", id: "env-table"}
|
= t('.env')
|
||||||
%thead
|
%table{class: "table table-hover collapse", id: "env-table"}
|
||||||
%tr
|
%thead
|
||||||
%th= t('.env_key')
|
|
||||||
%th= t('.env_value')
|
|
||||||
%tbody
|
|
||||||
- @env.each_pair do |key, value|
|
|
||||||
%tr
|
%tr
|
||||||
%td= key
|
%th= t('.env_key')
|
||||||
%td= value
|
%th= t('.env_value')
|
||||||
|
%tbody
|
||||||
|
- @env.each_pair do |key, value|
|
||||||
|
%tr
|
||||||
|
%td= key
|
||||||
|
%td= value
|
||||||
|
|
||||||
:javascript
|
:javascript
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
45
app/views/misc/update_fluentd_ui.html.haml
Normal file
45
app/views/misc/update_fluentd_ui.html.haml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
.panel.panel-default
|
||||||
|
.panel-heading
|
||||||
|
= t('.update_title')
|
||||||
|
.panel-body
|
||||||
|
#processing
|
||||||
|
= icon('fa-lg fa-gear fa-spin')
|
||||||
|
= t('.updating')
|
||||||
|
#finished{style: "display: none"}
|
||||||
|
= icon('fa-lg fa-check')
|
||||||
|
= t('.update_finish')
|
||||||
|
%p= link_to t('misc.information.page_title'), misc_information_path
|
||||||
|
#failed{style: "display: none"}
|
||||||
|
= icon('fa-lg fa-exclamation-circle')
|
||||||
|
= t('.failed')
|
||||||
|
%p= link_to t('misc.information.page_title'), misc_information_path
|
||||||
|
|
||||||
|
:javascript
|
||||||
|
var CURRENT_PID = "#{@current_pid}";
|
||||||
|
|
||||||
|
function ping() {
|
||||||
|
setTimeout(function(){
|
||||||
|
jQuery.ajax({
|
||||||
|
url: "#{misc_upgrading_status_path}",
|
||||||
|
type: "GET",
|
||||||
|
data: { old_pid: CURRENT_PID }
|
||||||
|
})
|
||||||
|
.fail(ping)
|
||||||
|
.done(function(status){
|
||||||
|
switch(status) {
|
||||||
|
case "updating":
|
||||||
|
ping();
|
||||||
|
break;
|
||||||
|
case "failed":
|
||||||
|
jQuery('#processing').hide();
|
||||||
|
jQuery('#failed').show();
|
||||||
|
break;
|
||||||
|
case "finished":
|
||||||
|
jQuery('#processing').hide();
|
||||||
|
jQuery('#finished').show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
ping();
|
@ -1,8 +1,13 @@
|
|||||||
= render partial: "shared/error"
|
.login-panel.panel.panel-default
|
||||||
= form_for(:session, url: sessions_path) do |f|
|
.panel-heading
|
||||||
%div.form-group
|
%h3.panel-title
|
||||||
= f.text_field :name, placeholder: "Name"
|
= t('messages.please_sign_in')
|
||||||
%div.form-group
|
.panel-body
|
||||||
= f.password_field :password, placeholder: "Password"
|
= render partial: "shared/error"
|
||||||
|
= form_for(:session, url: sessions_path) do |f|
|
||||||
|
%div.form-group
|
||||||
|
= f.text_field :name, placeholder: "Name"
|
||||||
|
%div.form-group
|
||||||
|
= f.password_field :password, placeholder: "Password"
|
||||||
|
|
||||||
= submit_tag t("terms.sign_in"), class: "btn btn-success"
|
= submit_tag t("terms.sign_in"), class: "btn btn-success"
|
||||||
|
@ -5,4 +5,6 @@
|
|||||||
- if flash[:success]
|
- if flash[:success]
|
||||||
%p.alert.alert-success
|
%p.alert.alert-success
|
||||||
=raw flash[:success]
|
=raw flash[:success]
|
||||||
|
- if flash[:info]
|
||||||
|
%p.alert.alert-info
|
||||||
|
=raw flash[:info]
|
||||||
|
38
app/workers/fluentd_ui_restart.rb
Normal file
38
app/workers/fluentd_ui_restart.rb
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
class FluentdUiRestart
|
||||||
|
include SuckerPunch::Job
|
||||||
|
|
||||||
|
LOCK = []
|
||||||
|
|
||||||
|
def lock!
|
||||||
|
raise "update process is still running" if LOCK.present?
|
||||||
|
LOCK << true
|
||||||
|
end
|
||||||
|
|
||||||
|
def unlock!
|
||||||
|
LOCK.shift
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform
|
||||||
|
lock!
|
||||||
|
sleep 5 # delay for render updating HTML
|
||||||
|
|
||||||
|
# NOTE: install will be failed before released fluentd-ui gem
|
||||||
|
SuckerPunch.logger.info "[restart] install new fluentd-ui"
|
||||||
|
Plugin.new(gem_name: "fluentd-ui").install!
|
||||||
|
|
||||||
|
if Rails.env.production?
|
||||||
|
cmd = %W(#{Rails.root}/bin/fluentd-ui start)
|
||||||
|
else
|
||||||
|
cmd = %W(bundle exec rails s)
|
||||||
|
end
|
||||||
|
|
||||||
|
SuckerPunch.logger.info "[restart] will restart"
|
||||||
|
Bundler.with_clean_env do
|
||||||
|
restarter = "#{Rails.root}/bin/fluentd-ui-restart"
|
||||||
|
Process.spawn(*[restarter, $$.to_s, *cmd, *ARGV]) && Process.kill(:TERM, $$)
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
# don't reach here if restart is successful
|
||||||
|
unlock!
|
||||||
|
end
|
||||||
|
end
|
15
app/workers/fluentd_ui_update_check.rb
Normal file
15
app/workers/fluentd_ui_update_check.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
class FluentdUiUpdateCheck
|
||||||
|
include SuckerPunch::Job
|
||||||
|
|
||||||
|
def perform
|
||||||
|
pl = Plugin.new(gem_name: "fluentd-ui")
|
||||||
|
if pl.gem_versions # NOTE: fluentd-ui is not released yet, so `pl.latest_version` will fail for now
|
||||||
|
FluentdUI.latest_version = pl.latest_version
|
||||||
|
end
|
||||||
|
later(3600) # will be checked every hour
|
||||||
|
end
|
||||||
|
|
||||||
|
def later(sec)
|
||||||
|
after(sec) { perform }
|
||||||
|
end
|
||||||
|
end
|
12
bin/fluentd-ui-restart
Executable file
12
bin/fluentd-ui-restart
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
pid = ARGV.shift
|
||||||
|
begin
|
||||||
|
loop do
|
||||||
|
# wait old fluentd-ui process shutdown
|
||||||
|
Process.kill(0, pid.to_i)
|
||||||
|
sleep 0.1
|
||||||
|
end
|
||||||
|
rescue Errno::ESRCH
|
||||||
|
exec(*ARGV)
|
||||||
|
end
|
@ -38,5 +38,7 @@ module FluentdUi
|
|||||||
# If AR will be used, please comment in and check timezone.
|
# If AR will be used, please comment in and check timezone.
|
||||||
# config.active_record.default_timezone = :local
|
# config.active_record.default_timezone = :local
|
||||||
# config.time_zone =
|
# config.time_zone =
|
||||||
|
|
||||||
|
require Rails.root.join("lib", "fluentd-ui")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ en:
|
|||||||
need_restart: need to restart fluentd-ui
|
need_restart: need to restart fluentd-ui
|
||||||
please_sign_in: Sign in
|
please_sign_in: Sign in
|
||||||
destroy_succeed_fluentd_setting: Deleted fluentd setting
|
destroy_succeed_fluentd_setting: Deleted fluentd setting
|
||||||
|
available_new_fluentd_ui: 'fluentd-ui %{version} is available. <a href="%{update_url}">Go to system information page</a>'
|
||||||
|
|
||||||
terms: &terms
|
terms: &terms
|
||||||
sign_in: Sign in
|
sign_in: Sign in
|
||||||
@ -186,6 +187,14 @@ en:
|
|||||||
env_key: Key
|
env_key: Key
|
||||||
env_value: Value
|
env_value: Value
|
||||||
page_title: System Information
|
page_title: System Information
|
||||||
|
update_fluentd_ui: Update fluentd-ui
|
||||||
|
update_fluentd_ui_caution: "Note: fluentd will not restart"
|
||||||
|
update_fluentd_ui:
|
||||||
|
<<: *misc_common
|
||||||
|
update_title: Updating fluentd-ui
|
||||||
|
updating: Updating..
|
||||||
|
update_finish: Update finished!
|
||||||
|
failed: Failed to update. Please see fluentd-ui log
|
||||||
|
|
||||||
tutorials:
|
tutorials:
|
||||||
common: &tutorials_common
|
common: &tutorials_common
|
||||||
|
@ -3,6 +3,7 @@ ja:
|
|||||||
need_restart: fluentd-uiの再起動が必要です
|
need_restart: fluentd-uiの再起動が必要です
|
||||||
please_sign_in: ログイン
|
please_sign_in: ログイン
|
||||||
destroy_succeed_fluentd_setting: fluentdの設定を削除しました
|
destroy_succeed_fluentd_setting: fluentdの設定を削除しました
|
||||||
|
available_new_fluentd_ui: 'fluentd-ui %{version}にアップデートできます。<a href="%{update_url}">システム情報ページへ</a>'
|
||||||
|
|
||||||
terms: &terms
|
terms: &terms
|
||||||
sign_in: ログイン
|
sign_in: ログイン
|
||||||
@ -182,6 +183,14 @@ ja:
|
|||||||
env_key: キー
|
env_key: キー
|
||||||
env_value: 値
|
env_value: 値
|
||||||
page_title: システム情報
|
page_title: システム情報
|
||||||
|
update_fluentd_ui: fluentd-uiを更新
|
||||||
|
update_fluentd_ui_caution: ※fluentdは再起動されません
|
||||||
|
update_fluentd_ui:
|
||||||
|
<<: *misc_common
|
||||||
|
update_title: fluentd-ui 更新
|
||||||
|
updating: 更新中
|
||||||
|
update_finish: 更新が完了しました
|
||||||
|
failed: 更新に失敗しました。fluentd-uiのログをご確認ください
|
||||||
|
|
||||||
tutorials:
|
tutorials:
|
||||||
common: &tutorials_common
|
common: &tutorials_common
|
||||||
|
@ -37,6 +37,8 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
get "misc" => "misc#show"
|
get "misc" => "misc#show"
|
||||||
get "misc/information"
|
get "misc/information"
|
||||||
|
post "misc/update_fluentd_ui"
|
||||||
|
get "misc/upgrading_status"
|
||||||
|
|
||||||
namespace :polling do
|
namespace :polling do
|
||||||
get "alerts"
|
get "alerts"
|
||||||
|
@ -1,2 +1,16 @@
|
|||||||
module FluentdUI
|
module FluentdUI
|
||||||
|
def self.latest_version=(version)
|
||||||
|
@latest = version
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.latest_version
|
||||||
|
@latest
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.update_available?
|
||||||
|
return unless @latest
|
||||||
|
latest = Gem::Version.new(@latest)
|
||||||
|
current = Gem::Version.new(::FluentdUI::VERSION)
|
||||||
|
latest > current
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user