Module: Dory::Systemd
- Defined in:
- lib/dory/systemd.rb
Class Method Summary collapse
- .has_systemd? ⇒ Boolean
- .set_systemd_service(service:, up:) ⇒ Object
- .systemd_service_enabled?(service) ⇒ Boolean
- .systemd_service_installed?(service) ⇒ Boolean
- .systemd_service_running?(service) ⇒ Boolean
- .up_delay_seconds ⇒ Object
Class Method Details
.has_systemd? ⇒ Boolean
9 10 11 |
# File 'lib/dory/systemd.rb', line 9 def self.has_systemd? Sh.run_command('which systemctl').success? end |
.set_systemd_service(service:, up:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Boolean
23 24 25 26 |
# 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) ⇒ Boolean
13 14 15 16 |
# 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) ⇒ Boolean
18 19 20 21 |
# 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 |