diff options
author | John Keiser <jkeiser@opscode.com> | 2013-09-16 16:43:30 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-09-16 16:43:30 -0700 |
commit | dc1dd7f5ec1cd791b08ff03d2f9a4e955e119d4a (patch) | |
tree | 2c1c7237d1e7ef21b7719c5a9471ddbca94f49ae | |
parent | 8fa661058877d5b465f4969e8fef9475af8f96a8 (diff) | |
download | chef-dc1dd7f5ec1cd791b08ff03d2f9a4e955e119d4a.tar.gz |
Use Chef::Config defaults for lockfile default
-rw-r--r-- | lib/chef/client.rb | 2 | ||||
-rw-r--r-- | lib/chef/config.rb | 6 | ||||
-rw-r--r-- | lib/chef/run_lock.rb | 12 | ||||
-rw-r--r-- | spec/functional/run_lock_spec.rb | 3 | ||||
-rw-r--r-- | spec/unit/run_lock_spec.rb | 5 |
5 files changed, 10 insertions, 18 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 33313290ee..3a5f112b0c 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -467,7 +467,7 @@ class Chef # === Returns # true:: Always returns true. def do_run - runlock = RunLock.new(Chef::Config) + runlock = RunLock.new(Chef::Config.lockfile) runlock.acquire # don't add code that may fail before entering this section to be sure to release lock begin diff --git a/lib/chef/config.rb b/lib/chef/config.rb index 725815681a..bb49a89fe6 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -222,14 +222,12 @@ class Chef # Where backups of chef-managed files should go default :file_backup_path, platform_specific_path('/var/chef/backup') - # By default, chef-client (or solo) creates a lockfile in - # `file_cache_path`/chef-client-running.pid - # If `lockfile` is explicitly set, this path will be used instead. + # The chef-client (or solo) lockfile. # # If your `file_cache_path` resides on a NFS (or non-flock()-supporting # fs), it's recommended to set this to something like # '/tmp/chef-client-running.pid' - default :lockfile, nil + default(:lockfile) { "#{file_cache_path}#{platform_path_separator}chef-client-running.pid" } ## Daemonization Settings ## # What user should Chef run as? diff --git a/lib/chef/run_lock.rb b/lib/chef/run_lock.rb index 50046c2396..4bde09de54 100644 --- a/lib/chef/run_lock.rb +++ b/lib/chef/run_lock.rb @@ -34,15 +34,9 @@ class Chef # Create a new instance of RunLock # === Arguments - # * config::: This will generally be the `Chef::Config`, but any Hash-like - # object with Symbol keys will work. See 'Parameters' section. - # === Parameters/Config - # * :lockfile::: if set, this will be used as the full path to the lockfile. - # * :file_cache_path::: if `:lockfile` is not set, the lock file will be - # named "chef-client-running.pid" and be placed in the directory given by - # `:file_cache_path` - def initialize(config) - @runlock_file = config[:lockfile] || "#{config[:file_cache_path]}/chef-client-running.pid" + # * :lockfile::: the full path to the lockfile. + def initialize(lockfile) + @runlock_file = lockfile @runlock = nil end diff --git a/spec/functional/run_lock_spec.rb b/spec/functional/run_lock_spec.rb index 7dc23d41fd..41f600ad88 100644 --- a/spec/functional/run_lock_spec.rb +++ b/spec/functional/run_lock_spec.rb @@ -31,7 +31,6 @@ describe Chef::RunLock do "/tmp/#{Kernel.rand(Time.now.to_i + Process.pid)}" end - let(:file_cache_path){ "/var/chef/cache" } let(:lockfile){ "#{random_temp_root}/this/long/path/does/not/exist/chef-client-running.pid" } # make sure to start with a clean slate. @@ -161,7 +160,7 @@ describe Chef::RunLock do ## # Run lock is the system under test - let!(:run_lock) { Chef::RunLock.new(:file_cache_path => file_cache_path, :lockfile => lockfile) } + let!(:run_lock) { Chef::RunLock.new(lockfile) } it "creates the full path to the lockfile" do lambda { run_lock.acquire }.should_not raise_error(Errno::ENOENT) diff --git a/spec/unit/run_lock_spec.rb b/spec/unit/run_lock_spec.rb index 4e62b110b9..e054c4899c 100644 --- a/spec/unit/run_lock_spec.rb +++ b/spec/unit/run_lock_spec.rb @@ -22,12 +22,13 @@ describe Chef::RunLock do describe "when first created" do it "locates the lockfile in the file cache path by default" do - run_lock = Chef::RunLock.new(:file_cache_path => "/var/chef/cache", :lockfile => nil) + run_lock = Chef::RunLock.new(Chef::Config.lockfile) run_lock.runlock_file.should == "/var/chef/cache/chef-client-running.pid" end it "locates the lockfile in the user-configured path when set" do - run_lock = Chef::RunLock.new(:file_cache_path => "/var/chef/cache", :lockfile => "/tmp/chef-client-running.pid") + Chef::Config.lockfile = "/tmp/chef-client-running.pid" + run_lock = Chef::RunLock.new(Chef::Config.lockfile) run_lock.runlock_file.should == "/tmp/chef-client-running.pid" end end |