Sha256: 2884e25d0fa68cd916ef6ead2bec6d3fb55e2e0b766b5a2f6eca4dcb50eab8a7

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 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 => [:redhat, :suse]
  defaultfor :osfamily => [:archlinux]

  def self.instances
    i = []
    output = systemctl('list-units', '--full', '--all',  '--no-pager')
    output.scan(/^(\S+)\s+(loaded|error)\s+(active|inactive)\s+(active|waiting|running|plugged|mounted|dead|exited|listening|elapsed)\s*?(\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}"
  end

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

    :true
  end

  def status
    begin
      output = 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}"
  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

7 entries across 7 versions & 1 rubygems

Version Path
puppet-3.2.4 lib/puppet/provider/service/systemd.rb
puppet-3.2.3 lib/puppet/provider/service/systemd.rb
puppet-3.2.3.rc1 lib/puppet/provider/service/systemd.rb
puppet-3.2.2 lib/puppet/provider/service/systemd.rb
puppet-3.2.1 lib/puppet/provider/service/systemd.rb
puppet-3.2.1.rc1 lib/puppet/provider/service/systemd.rb
puppet-3.2.0.rc2 lib/puppet/provider/service/systemd.rb