Sha256: 8b2774ead87ec995eed0d537c0b0f2421da63e369feb12eceb3633f6373764f5

Contents?: true

Size: 1.37 KB

Versions: 20

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

Puppet::Type.type(:service).provide :bsd, :parent => :init do
  desc <<-EOT
    Generic BSD form of `init`-style service management with `rc.d`.

    Uses `rc.conf.d` for service enabling and disabling.
  EOT

  confine 'os.name' => [:freebsd, :dragonfly]

  def rcconf_dir
    '/etc/rc.conf.d'
  end

  def self.defpath
    superclass.defpath
  end

  # remove service file from rc.conf.d to disable it
  def disable
    rcfile = File.join(rcconf_dir, @resource[:name])
    File.delete(rcfile) if Puppet::FileSystem.exist?(rcfile)
  end

  # if the service file exists in rc.conf.d then it's already enabled
  def enabled?
    rcfile = File.join(rcconf_dir, @resource[:name])
    return :true if Puppet::FileSystem.exist?(rcfile)

    :false
  end

  # enable service by creating a service file under rc.conf.d with the
  # proper contents
  def enable
    Dir.mkdir(rcconf_dir) unless Puppet::FileSystem.exist?(rcconf_dir)
    rcfile = File.join(rcconf_dir, @resource[:name])
    File.open(rcfile, File::WRONLY | File::APPEND | File::CREAT, 0o644) { |f|
      f << "%s_enable=\"YES\"\n" % @resource[:name]
    }
  end

  # Override stop/start commands to use one<cmd>'s and the avoid race condition
  # where provider tries to stop/start the service before it is enabled
  def startcmd
    [initscript, :onestart]
  end

  def stopcmd
    [initscript, :onestop]
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/provider/service/bsd.rb
puppet-8.10.0-x86-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.10.0-x64-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.10.0-universal-darwin lib/puppet/provider/service/bsd.rb
puppet-8.9.0 lib/puppet/provider/service/bsd.rb
puppet-8.9.0-x86-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.9.0-x64-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.9.0-universal-darwin lib/puppet/provider/service/bsd.rb
puppet-8.8.1 lib/puppet/provider/service/bsd.rb
puppet-8.8.1-x86-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.8.1-x64-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.8.1-universal-darwin lib/puppet/provider/service/bsd.rb
puppet-8.7.0 lib/puppet/provider/service/bsd.rb
puppet-8.7.0-x86-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.7.0-x64-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.7.0-universal-darwin lib/puppet/provider/service/bsd.rb
puppet-8.6.0 lib/puppet/provider/service/bsd.rb
puppet-8.6.0-x86-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.6.0-x64-mingw32 lib/puppet/provider/service/bsd.rb
puppet-8.6.0-universal-darwin lib/puppet/provider/service/bsd.rb