lib/chef/daemon.rb in chef-10.34.6 vs lib/chef/daemon.rb in chef-11.0.0.beta.0
- old
+ new
@@ -44,14 +44,11 @@
File.umask Chef::Config[:umask]
$stdin.reopen("/dev/null")
$stdout.reopen("/dev/null", "a")
$stderr.reopen($stdout)
save_pid_file
- at_exit {
- Chef::Log.debug("daemon pid #{Process.pid} in at_exit handler")
- remove_pid_file
- }
+ at_exit { remove_pid_file }
rescue NotImplementedError => e
Chef::Application.fatal!("There is no fork: #{e.message}")
end
else
Chef::Application.fatal!("Chef is already running pid #{pid}")
@@ -108,30 +105,18 @@
rescue Errno::EACCES => e
Chef::Application.fatal!("Failed store pid in #{File.dirname(file)}, permission denied: #{e.message}")
end
begin
- pid = Process.pid.to_s
- File.open(file, "w") { |f| f.write(pid) }
- Chef::Log.debug("Wrote #{pid} to #{file}")
+ File.open(file, "w") { |f| f.write(Process.pid.to_s) }
rescue Errno::EACCES => e
Chef::Application.fatal!("Couldn't write to pidfile #{file}, permission denied: #{e.message}")
end
end
# Delete the PID from the filesystem
def remove_pid_file
- return unless File.exists?(pid_file)
-
- daemon_pid = pid_from_file
- my_pid = Process.pid
- if daemon_pid != my_pid
- Chef::Log.debug("My pid is #{my_pid}; not removing #{pid_file} which contains #{daemon_pid}")
- return
- end
-
- FileUtils.rm(pid_file)
- Chef::Log.debug("Removed #{pid_file}")
+ FileUtils.rm(pid_file) if File.exists?(pid_file)
end
# Change process user/group to those specified in Chef::Config
#
def change_privilege