Sha256: 69100f8246bd63bacca2aa05bd342b7b30e48dc4b07276b77842103ec04dc6b0

Contents?: true

Size: 1.5 KB

Versions: 34

Compression:

Stored size: 1.5 KB

Contents

# Manage systemd services using /bin/systemctl

Puppet::Type.type(:service).provide :systemd, :parent => :base do
  desc "Manages `systemd` services using `systemctl`."

  commands :systemctl => "systemctl"

  defaultfor :osfamily => [:archlinux]
  defaultfor :osfamily => :redhat, :operatingsystemmajrelease => "7"

  def self.instances
    i = []
    output = systemctl('list-unit-files', '--type', 'service', '--full', '--all',  '--no-pager')
    output.scan(/^(\S+)\s+(disabled|enabled)\s*$/i).each do |m|
      i << new(:name => m[0])
    end
    return i
  rescue Puppet::ExecutionFailure
    return []
  end

  def disable
    output = systemctl(:disable, @resource[:name])
  rescue Puppet::ExecutionFailure
    raise Puppet::Error, "Could not disable #{self.name}: #{output}", $!.backtrace
  end

  def enabled?
    begin
      systemctl("is-enabled", @resource[:name])
    rescue Puppet::ExecutionFailure
      return :false
    end

    :true
  end

  def status
    begin
      systemctl("is-active", @resource[:name])
    rescue Puppet::ExecutionFailure
      return :stopped
    end
    return :running
  end

  def enable
    output = systemctl("enable", @resource[:name])
  rescue Puppet::ExecutionFailure
    raise Puppet::Error, "Could not enable #{self.name}: #{output}", $!.backtrace
  end

  def restartcmd
    [command(:systemctl), "restart", @resource[:name]]
  end

  def startcmd
    [command(:systemctl), "start", @resource[:name]]
  end

  def stopcmd
    [command(:systemctl), "stop", @resource[:name]]
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.8.0 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.7.3 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-retrospec-0.7.2 vendor/gems/puppet-3.7.3/lib/puppet/provider/service/systemd.rb
puppet-3.7.4 lib/puppet/provider/service/systemd.rb
puppet-3.7.4-x86-mingw32 lib/puppet/provider/service/systemd.rb
puppet-3.7.4-x64-mingw32 lib/puppet/provider/service/systemd.rb
puppet-3.7.3 lib/puppet/provider/service/systemd.rb
puppet-3.7.3-x86-mingw32 lib/puppet/provider/service/systemd.rb
puppet-3.7.3-x64-mingw32 lib/puppet/provider/service/systemd.rb
puppet-3.7.2 lib/puppet/provider/service/systemd.rb
puppet-3.7.2-x86-mingw32 lib/puppet/provider/service/systemd.rb
puppet-3.7.2-x64-mingw32 lib/puppet/provider/service/systemd.rb