module Dory::Systemd
Public Class Methods
has_systemd?()
click to toggle source
# File lib/dory/systemd.rb, line 9 def self.has_systemd? Sh.run_command('which systemctl').success? end
set_systemd_service(service:, up:)
click to toggle source
# File lib/dory/systemd.rb, line 28 def self.set_systemd_service(service:, up:) action = up ? 'start' : 'stop' puts "Requesting sudo to #{action} #{service}".green retval = Sh.run_command("sudo systemctl #{action} #{service}").success? # We need to wait a few seconds for init if putting stuff up to avoid race conditions if up puts "Waiting #{self.up_delay_seconds} seconds for #{service} to start ...".green sleep(self.up_delay_seconds) end retval end
systemd_service_enabled?(service)
click to toggle source
# File lib/dory/systemd.rb, line 23 def self.systemd_service_enabled?(service) return false unless self.has_systemd? !!(Sh.run_command("systemctl status #{service} | head -3").stdout.gsub(/Loaded.*?;/, '') =~ /^\s*enabled;/) end
systemd_service_installed?(service)
click to toggle source
# File lib/dory/systemd.rb, line 13 def self.systemd_service_installed?(service) return false unless self.has_systemd? !(Sh.run_command("systemctl status #{service} | head -1").stdout =~ /not-found/) end
systemd_service_running?(service)
click to toggle source
# File lib/dory/systemd.rb, line 18 def self.systemd_service_running?(service) return false unless self.has_systemd? !!(Sh.run_command("systemctl status #{service} | head -3").stdout =~ /Active:\s+active.*running/) end
up_delay_seconds()
click to toggle source
# File lib/dory/systemd.rb, line 5 def self.up_delay_seconds Dory::Config.settings[:dory][:dnsmasq][:service_start_delay] || 5 end