Class: Puppet::Util::Pidlock
- Defined in:
- lib/vendor/puppet/util/pidlock.rb
Instance Attribute Summary collapse
-
#lockfile ⇒ Object
readonly
Returns the value of attribute lockfile.
Instance Method Summary collapse
- #anonymous? ⇒ Boolean
-
#initialize(lockfile) ⇒ Pidlock
constructor
A new instance of Pidlock.
- #lock(opts = {}) ⇒ Object
- #locked? ⇒ Boolean
- #mine? ⇒ Boolean
- #unlock(opts = {}) ⇒ Object
Constructor Details
#initialize(lockfile) ⇒ Pidlock
Returns a new instance of Pidlock.
6 7 8 |
# File 'lib/vendor/puppet/util/pidlock.rb', line 6 def initialize(lockfile) @lockfile = lockfile end |
Instance Attribute Details
#lockfile ⇒ Object (readonly)
Returns the value of attribute lockfile.
4 5 6 |
# File 'lib/vendor/puppet/util/pidlock.rb', line 4 def lockfile @lockfile end |
Instance Method Details
#anonymous? ⇒ Boolean
25 26 27 28 |
# File 'lib/vendor/puppet/util/pidlock.rb', line 25 def anonymous? return false unless File.exists?(@lockfile) File.read(@lockfile) == "" end |
#lock(opts = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vendor/puppet/util/pidlock.rb', line 30 def lock(opts = {}) opts = {:anonymous => false}.merge(opts) if locked? mine? else if opts[:anonymous] File.open(@lockfile, 'w') { |fd| true } else File.open(@lockfile, "w") { |fd| fd.write(Process.pid) } end true end end |
#locked? ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vendor/puppet/util/pidlock.rb', line 10 def locked? clear_if_stale return true if File.exists? @lockfile # HACK! There was a temporary change to the lockfile behavior introduced in 2.7.10 and 2.7.11, and reverted # in 2.7.12. We need to pull some chicanery to be backwards-compatible with those versions. For more info, # see the comments on the method... and this hack should be removed for the 3.x series. handle_2_7_10_disabled_lockfile File.exists? @lockfile end |
#mine? ⇒ Boolean
21 22 23 |
# File 'lib/vendor/puppet/util/pidlock.rb', line 21 def mine? Process.pid == lock_pid end |