Skip to content

Commit 755efff

Browse files
jaymzhmeta-codesync[bot]
authored andcommitted
Move default lockfile location (#103)
Summary: `/var/lock/subsys` was meant for SysV startup serialization, and was never the right location for our lockfile. Moreover, recent systemd releases no longer keep the `legacy.conf` configuration that creates `/var/lock/subsys`, so this means chefctl no longer works out of the box. Move the default to something more modern *NOTE*: If Meta doesn't explicitly set a `lock_file` setting in their `chefctl-config.rb`, they should before merging this. Signed-off-by: Phil Dibowitz <phil@ipom.com> Pull Request resolved: #103 Reviewed By: AadityaNair Differential Revision: D113597252 Pulled By: dafyddcrosby fbshipit-source-id: c9cf6759254ab95c911942391f06b4a89528d57b
1 parent edfb513 commit 755efff

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

chefctl/sample_configs/chefctl-config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
# immediate false
4141

4242
# The lock file to use for chefctl.
43-
# lock_file '/var/lock/subsys/chefctl'
43+
# lock_file '/var/lock/chefctl.lock'
4444

4545
# How long to wait for the lock to become available.
4646
# lock_time 1800

chefctl/src/chefctl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ module Config
150150
immediate false
151151

152152
# The lock file to use for chefctl.
153-
lock_file '/var/lock/subsys/chefctl'
153+
lock_file '/var/lock/chefctl.lock'
154154

155155
# How long to wait for the lock to become available.
156156
lock_time 1800

chefctl/src/spec/chefctl_spec.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def lib
9292
lockfile = double('lockfile')
9393

9494
# open 'a+' done in wait_for_lock
95-
allow(File).to receive(:open).with('/var/lock/subsys/chefctl', 'a+') { lockfile }
95+
allow(File).to receive(:open).with('/var/lock/chefctl.lock', 'a+') { lockfile }
9696
allow(lockfile).to receive(:flock).and_return(true)
9797

9898
allow(lockfile).to receive(:close)
@@ -106,29 +106,29 @@ def lib
106106
it 'can still acquire lock if first attempt fails' do
107107
# First failed attempt
108108
allow(Chefctl).
109-
to receive_message_chain(:logger, :debug).with('Trying lock /var/lock/subsys/chefctl')
109+
to receive_message_chain(:logger, :debug).with('Trying lock /var/lock/chefctl.lock')
110110
allow(main).to receive(:wait_for_lock).with(-1).and_return(false)
111111

112112
# Second attempt
113113
expect(main).to receive(:wait_for_lock).with(1800).and_call_original # second attempt
114114

115115
# Get pid of other lock file
116116
other_lockfile = double('other_lockfile')
117-
expect(File).to receive(:open).with('/var/lock/subsys/chefctl', 'r').and_yield(other_lockfile)
117+
expect(File).to receive(:open).with('/var/lock/chefctl.lock', 'r').and_yield(other_lockfile)
118118
expect(other_lockfile).to receive(:read).and_return('888888')
119119

120120
expect(Chefctl).
121121
to receive_message_chain(:logger, :info).
122-
with('/var/lock/subsys/chefctl is locked by 888888, waiting up to 1800 seconds.')
122+
with('/var/lock/chefctl.lock is locked by 888888, waiting up to 1800 seconds.')
123123

124124
# open 'a+' done in wait_for_lock
125125
lockfile = double('lockfile')
126-
allow(File).to receive(:open).with('/var/lock/subsys/chefctl', 'a+') { lockfile }
126+
allow(File).to receive(:open).with('/var/lock/chefctl.lock', 'a+') { lockfile }
127127
allow(lockfile).to receive(:flock).and_return(true)
128128

129129
# taking over the lock
130130
expect(Chefctl).
131-
to receive_message_chain(:logger, :debug).with('Lock acquired: /var/lock/subsys/chefctl')
131+
to receive_message_chain(:logger, :debug).with('Lock acquired: /var/lock/chefctl.lock')
132132
expect(lockfile).to receive(:truncate)
133133
expect(Process).to receive(:pid).and_return('123123')
134134
expect(lockfile).to receive(:write).with('123123')
@@ -140,29 +140,29 @@ def lib
140140
it 'can still acquire lock if first attempt fails' do
141141
# First failed attempt
142142
allow(Chefctl).
143-
to receive_message_chain(:logger, :debug).with('Trying lock /var/lock/subsys/chefctl')
143+
to receive_message_chain(:logger, :debug).with('Trying lock /var/lock/chefctl.lock')
144144
allow(main).to receive(:wait_for_lock).with(-1).and_return(false)
145145

146146
# Second attempt
147147
expect(main).to receive(:wait_for_lock).with(1800).and_call_original # second attempt
148148

149149
# Get pid of other lock file
150150
other_lockfile = double('other_lockfile')
151-
expect(File).to receive(:open).with('/var/lock/subsys/chefctl', 'r').and_yield(other_lockfile)
151+
expect(File).to receive(:open).with('/var/lock/chefctl.lock', 'r').and_yield(other_lockfile)
152152
expect(other_lockfile).to receive(:read).and_return('888888')
153153

154154
expect(Chefctl).
155155
to receive_message_chain(:logger, :info).
156-
with('/var/lock/subsys/chefctl is locked by 888888, waiting up to 1800 seconds.')
156+
with('/var/lock/chefctl.lock is locked by 888888, waiting up to 1800 seconds.')
157157

158158
# open 'a+' done in wait_for_lock
159159
lockfile = double('lockfile')
160-
allow(File).to receive(:open).with('/var/lock/subsys/chefctl', 'a+') { lockfile }
160+
allow(File).to receive(:open).with('/var/lock/chefctl.lock', 'a+') { lockfile }
161161
allow(lockfile).to receive(:flock).and_return(true)
162162

163163
# taking over the lock
164164
expect(Chefctl).
165-
to receive_message_chain(:logger, :debug).with('Lock acquired: /var/lock/subsys/chefctl')
165+
to receive_message_chain(:logger, :debug).with('Lock acquired: /var/lock/chefctl.lock')
166166
expect(lockfile).to receive(:truncate)
167167
expect(Process).to receive(:pid).and_return('123123')
168168
expect(lockfile).to receive(:write).with('123123')
@@ -174,30 +174,30 @@ def lib
174174
it 'does not crash on race between wait_for_lock and read on missing lockfile' do
175175
# First failed attempt
176176
allow(Chefctl).
177-
to receive_message_chain(:logger, :debug).with('Trying lock /var/lock/subsys/chefctl')
177+
to receive_message_chain(:logger, :debug).with('Trying lock /var/lock/chefctl.lock')
178178
allow(main).to receive(:wait_for_lock).with(-1).and_return(false)
179179

180180
# Second attempt
181181
expect(main).to receive(:wait_for_lock).with(1800).and_call_original # second attempt
182182

183183
# Attempt to get pid of other lock file
184-
expect(File).to receive(:open).with('/var/lock/subsys/chefctl', 'r').and_raise(Errno::ENOENT)
184+
expect(File).to receive(:open).with('/var/lock/chefctl.lock', 'r').and_raise(Errno::ENOENT)
185185
expect(Chefctl).
186186
to receive_message_chain(:logger, :info).
187187
with('Possible lockfile race, re-running wait_for_lock')
188188

189189
expect(Chefctl).
190190
to receive_message_chain(:logger, :info).
191-
with('/var/lock/subsys/chefctl is locked by another process, waiting up to 1800 seconds.')
191+
with('/var/lock/chefctl.lock is locked by another process, waiting up to 1800 seconds.')
192192

193193
# open 'a+' done in wait_for_lock
194194
lockfile = double('lockfile')
195-
allow(File).to receive(:open).with('/var/lock/subsys/chefctl', 'a+') { lockfile }
195+
allow(File).to receive(:open).with('/var/lock/chefctl.lock', 'a+') { lockfile }
196196
allow(lockfile).to receive(:flock).and_return(true)
197197

198198
# taking over the lock
199199
expect(Chefctl).
200-
to receive_message_chain(:logger, :debug).with('Lock acquired: /var/lock/subsys/chefctl')
200+
to receive_message_chain(:logger, :debug).with('Lock acquired: /var/lock/chefctl.lock')
201201
expect(lockfile).to receive(:truncate)
202202
expect(Process).to receive(:pid).and_return('123123')
203203
expect(lockfile).to receive(:write).with('123123')
@@ -235,7 +235,7 @@ def lib
235235

236236
it 'lock still yields the block when locking is disabled' do
237237
# Stub to prevent filesystem access if disable_locking guard fails
238-
allow(File).to receive(:open).with('/var/lock/subsys/chefctl', anything).
238+
allow(File).to receive(:open).with('/var/lock/chefctl.lock', anything).
239239
and_raise('locking should be disabled')
240240
yielded = false
241241
main.lock { yielded = true }

0 commit comments

Comments
 (0)