diff options
Diffstat (limited to 'lib/chef/daemon.rb')
-rw-r--r-- | lib/chef/daemon.rb | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/chef/daemon.rb b/lib/chef/daemon.rb index 9a3d5a884a..e5479905af 100644 --- a/lib/chef/daemon.rb +++ b/lib/chef/daemon.rb @@ -6,9 +6,9 @@ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -54,7 +54,7 @@ class Chef Chef::Application.fatal!("Chef is already running pid #{pid}") end end - + # Check if Chef is running based on the pid_file # ==== Returns # Boolean:: @@ -73,11 +73,11 @@ class Chef rescue Errno::EACCES => e Chef::Application.fatal!("You don't have access to the PID file at #{pid_file}: #{e.message}") end - + # Check if this process if forked from a Chef daemon # ==== Returns # Boolean:: - # True if this process is forked + # True if this process is forked # False if this process is not forked # def forked? @@ -91,7 +91,7 @@ class Chef false end end - + # Gets the pid file for @name # ==== Returns # String:: @@ -99,7 +99,7 @@ class Chef def pid_file Chef::Config[:pid_file] or "/tmp/#{@name}.pid" end - + # Suck the pid out of pid_file # ==== Returns # Integer:: @@ -112,7 +112,7 @@ class Chef rescue Errno::ENOENT, Errno::EACCES nil end - + # Store the PID on the filesystem # This uses the Chef::Config[:pid_file] option, or "/tmp/name.pid" otherwise # @@ -123,20 +123,20 @@ class Chef rescue Errno::EACCES => e Chef::Application.fatal!("Failed store pid in #{File.dirname(file)}, permission denied: #{e.message}") end - + begin 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 if not forked? then FileUtils.rm(pid_file) if File.exists?(pid_file) end - end + end # Change process user/group to those specified in Chef::Config # @@ -151,7 +151,7 @@ class Chef _change_privilege(Chef::Config[:user]) end end - + # Change privileges of the process to be the specified user and group # # ==== Parameters @@ -170,14 +170,14 @@ class Chef Chef::Application.fatal!("Failed to get UID for user #{user}, does it exist? #{e.message}") return false end - + begin target_gid = Etc.getgrnam(group).gid rescue ArgumentError => e Chef::Application.fatal!("Failed to get GID for group #{group}, does it exist? #{e.message}") return false end - + if (uid != target_uid) or (gid != target_gid) Process.initgroups(user, target_gid) Process::GID.change_privilege(target_gid) |