Class: DistribotUI::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/distribot-ui/command.rb

Constant Summary collapse

ROOT =
File.expand_path('../../../', __FILE__)

Instance Method Summary collapse

Instance Method Details

#setupObject



51
52
53
54
# File 'lib/distribot-ui/command.rb', line 51

def setup
  trap(:INT) { puts "\nStopping..." }
  system(*%W(bundle install))
end

#startObject



14
15
16
17
18
19
20
21
# File 'lib/distribot-ui/command.rb', line 14

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

#statusObject



36
37
38
39
40
41
42
43
44
# File 'lib/distribot-ui/command.rb', line 36

def status
  if pid && Process.kill(0, pid)
    puts "distribot-ui is running"
  else
    puts "distribot-ui is stopped"
  end
rescue Errno::ESRCH
  puts "distribot-ui is stopped"
end

#stopObject



26
27
28
29
30
31
# File 'lib/distribot-ui/command.rb', line 26

def stop
  Process.kill(:TERM, pid) if pid
rescue Errno::ESRCH
ensure
  puts "stopped"
end