Class: FluentdUiRestart

Inherits:
Object
  • Object
show all
Includes:
SuckerPunch::Job
Defined in:
app/workers/fluentd_ui_restart.rb

Constant Summary collapse

LOCK =
[]

Instance Method Summary collapse

Instance Method Details

#lock!Object



6
7
8
9
# File 'app/workers/fluentd_ui_restart.rb', line 6

def lock!
  raise "update process is still running" if locked?
  LOCK << true # dummy value
end

#locked?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/workers/fluentd_ui_restart.rb', line 11

def locked?
  LOCK.present?
end

#performObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/workers/fluentd_ui_restart.rb', line 19

def perform
  lock!

  # 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

#unlock!Object



15
16
17
# File 'app/workers/fluentd_ui_restart.rb', line 15

def unlock!
  LOCK.shift
end