class Lita::Daemon
Converts Lita to a daemon process. @deprecated Will be removed in Lita 5.0. Use your operating system's process manager instead.
Public Class Methods
new(pid_path, log_path, kill_existing)
click to toggle source
@param pid_path [String] The path to the PID file. @param log_path [String] The path to the log file. @param kill_existing [Boolean] Whether or not to kill existing processes.
# File lib/lita/daemon.rb, line 10 def initialize(pid_path, log_path, kill_existing) @pid_path = pid_path @log_path = log_path @kill_existing = kill_existing end
Public Instance Methods
daemonize()
click to toggle source
Converts Lita to a daemon process. @return [void]
# File lib/lita/daemon.rb, line 18 def daemonize handle_existing_process Process.daemon(true) File.open(@pid_path, "w") { |f| f.write(Process.pid) } set_up_logs at_exit { FileUtils.rm(@pid_path) if File.exist?(@pid_path) } end
Private Instance Methods
ensure_not_running()
click to toggle source
Abort if Lita is already running.
# File lib/lita/daemon.rb, line 29 def ensure_not_running abort I18n.t("lita.daemon.pid_exists", path: @pid_path) if File.exist?(@pid_path) end
handle_existing_process()
click to toggle source
Call the appropriate method depending on kill mode.
# File lib/lita/daemon.rb, line 34 def handle_existing_process if @kill_existing && File.exist?(@pid_path) kill_existing_process else ensure_not_running end end
kill_existing_process()
click to toggle source
Try to kill an existing process.
# File lib/lita/daemon.rb, line 43 def kill_existing_process pid = File.read(@pid_path).to_s.strip.to_i Process.kill("TERM", pid) rescue Errno::ESRCH, RangeError, Errno::EPERM abort I18n.t("lita.daemon.kill_failure", pid: pid) end
set_up_logs()
click to toggle source
Redirect the standard streams to a log file.
# File lib/lita/daemon.rb, line 51 def set_up_logs log_file = File.new(@log_path, "a") STDOUT.reopen(log_file) STDERR.reopen(log_file) STDERR.sync = STDOUT.sync = true end