Class: Puppet::Util::Pidlock
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/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/puppet/util/pidlock.rb', line 4 def lockfile @lockfile end |
Instance Method Details
#anonymous? ⇒ Boolean
19 20 21 22 |
# File 'lib/puppet/util/pidlock.rb', line 19 def anonymous? return false unless File.exists?(@lockfile) File.read(@lockfile) == "" end |
#lock(opts = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/puppet/util/pidlock.rb', line 24 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 |
# File 'lib/puppet/util/pidlock.rb', line 10 def locked? clear_if_stale File.exists? @lockfile end |
#mine? ⇒ Boolean
15 16 17 |
# File 'lib/puppet/util/pidlock.rb', line 15 def mine? Process.pid == lock_pid end |