文件操作 - bsd.rb
返回文件管理
返回主菜单
删除本文件
文件: /opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/provider/service/bsd.rb
编辑文件内容
# 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
修改文件时间
将文件时间修改为当前时间的前一年
删除文件