Class: ChefLocker
- Inherits:
-
Object
- Object
- ChefLocker
- Defined in:
- lib/chef_locker.rb
Overview
Instance Method Summary collapse
-
#initialize(output: $stdout) ⇒ ChefLocker
constructor
A new instance of ChefLocker.
-
#lock(message) ⇒ Object
Locks Chef runs (prevents Chef clients from converging).
Constructor Details
#initialize(output: $stdout) ⇒ ChefLocker
Returns a new instance of ChefLocker.
6 7 8 9 |
# File 'lib/chef_locker.rb', line 6 def initialize(output: $stdout) @output = output @runlock = Chef::RunLock.new(Chef::Config.lockfile) end |
Instance Method Details
#lock(message) ⇒ Object
Locks Chef runs (prevents Chef clients from converging)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/chef_locker.rb', line 14 def lock() = .to_s raise ArgumentError, "Message can't be blank" if .strip.empty? @runlock.acquire begin @output.puts 'Lock acquired' @runlock.save_pid @runlock.runlock.write(' ' + ) @runlock.runlock.fsync # Now we block until interrupted (there might be a better way to do this) loop { $stdin.read } ensure @runlock.release end end |