class Sv::Server
Attributes
app_dir[R]
Public Class Methods
new(app_dir)
click to toggle source
# File lib/sv/server.rb, line 12 def initialize(app_dir) @app_dir = app_dir end
Public Instance Methods
health_check()
click to toggle source
# File lib/sv/server.rb, line 68 def health_check if instances == 0 return end raise Error, "server not running" if not server_status.running? api.health_check end
print_config()
click to toggle source
# File lib/sv/server.rb, line 91 def print_config puts File.read(supervisor_config.generated_path) end
reopen_logs()
click to toggle source
# File lib/sv/server.rb, line 63 def reopen_logs return if not server_status.running? api.reopen_logs end
required_paths()
click to toggle source
# File lib/sv/server.rb, line 95 def required_paths paths = [ "#{app_dir}/tmp/sockets/", "#{app_dir}/tmp/pids/", "#{app_dir}/log/" ] paths.each do |path| path = Pathname.new(path) raise ::Sv::Error, "required path missing #{path}" if not path.exist? end end
restart(auto_start: false, wait: false)
click to toggle source
# File lib/sv/server.rb, line 42 def restart(auto_start: false, wait: false) stop if server_status.running? start auto_start: auto_start, wait: wait end
rolling_restart()
click to toggle source
# File lib/sv/server.rb, line 47 def rolling_restart init_once if not server_status.running? start auto_start: true, wait: true return end if instances == 0 puts "stopping supervisord: 0 instances" stop return end supervisor_config.generated_path rolling_restart = RollingRestart.new(config.jobs, api) rolling_restart.run end
start(auto_start: false, wait: false)
click to toggle source
# File lib/sv/server.rb, line 16 def start(auto_start: false, wait: false) init_once if instances == 0 puts "skipping supervisord start: 0 instances" return end if server_status.running? puts "supervisor already running with pid #{api.pid}" return end system "supervisord -c #{supervisor_config.generated_path}" puts "Started" api.start_jobs(wait: wait) if auto_start end
start_jobs()
click to toggle source
# File lib/sv/server.rb, line 76 def start_jobs api.start_jobs puts api.errors end
status()
click to toggle source
# File lib/sv/server.rb, line 81 def status if server_status.running? api.print_status puts "-"* 20 puts "active_groups: #{api.active_groups.size}" else puts "Stopped" end end
stop()
click to toggle source
# File lib/sv/server.rb, line 31 def stop init_once if server_status.stopped? puts "Stopped" return end api.shutdown server_status.wait_until_stopped puts "Stopped" end
Private Instance Methods
api()
click to toggle source
# File lib/sv/server.rb, line 113 def api @api ||= ::Sv::Api.new(config.socket_path) end
config()
click to toggle source
# File lib/sv/server.rb, line 109 def config @config ||= ::Sv::Config.new(app_dir) end
init_once()
click to toggle source
# File lib/sv/server.rb, line 125 def init_once @init_once ||= begin required_paths true end end
instances()
click to toggle source
# File lib/sv/server.rb, line 132 def instances @instances ||= config.jobs.reduce(0) { |memo, j| memo += j.numprocs } end
server_status()
click to toggle source
# File lib/sv/server.rb, line 117 def server_status @server_status ||= ::Sv::Status.new(config.socket_path) end
supervisor_config()
click to toggle source
# File lib/sv/server.rb, line 121 def supervisor_config @supervisor_config ||= ::Sv::Supervisor::Config.new(config) end