Sha256: a5be6256c89d7cd71336e28665a77e35edf790f07cf9cab8554ca178a0ae3992
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true module LifxDash class Daemonizer LOG_FILE = "/tmp/lifx_dash.log" def self.start(log_file = LOG_FILE) # fork process (skip IO redirect to /dev/null) Process.daemon(false, true) # show pid and log file info on stdout right away puts "[#{Process.pid}] Starting lifx_dash ... (daemon logging to #{log_file})" redirect_io(log_file) end # Free the STDIN/STDOUT/STDERR file descriptors and point them somewhere # sensible - inspired by daemons gem def self.redirect_io(log_file) STDIN.reopen '/dev/null' begin # ensure log file exists with good permissions FileUtils.mkdir_p(File.dirname(log_file), :mode => 0755) FileUtils.touch log_file File.chmod(0644, log_file) # reopen STOUT stream to file STDOUT.reopen log_file, 'a' STDOUT.sync = true rescue ::StandardError STDOUT.reopen '/dev/null' end # reopen STERR stream to STDOUT (file stream) STDERR.reopen STDOUT STDERR.sync = true rescue => e raise "#{self} - error: could not redirect IO - #{e.message}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lifx_dash-0.4.0 | lib/lifx_dash/daemonizer.rb |