@@ -38,15 +38,25 @@ def needing_restart?
38
38
# Perform a run with our client.
39
39
def run ( client_options = { } )
40
40
if disabled?
41
- Puppet . notice _ ( "Skipping run of %{client_class}; administratively disabled (Reason: '%{disable_message}'); \n Use 'puppet agent --enable' to re-enable." ) % { client_class : client_class , disable_message : disable_message }
41
+ log_disabled_message
42
42
return
43
43
end
44
44
45
45
result = nil
46
46
wait_for_lock_deadline = nil
47
47
block_run = Puppet ::Application . controlled_run do
48
- # splay may sleep for awhile!
49
- splay ( client_options . fetch ( :splay , Puppet [ :splay ] ) )
48
+ # splay may sleep for awhile when running onetime! If not onetime, then
49
+ # the job scheduler splays (only once) so that agents assign themselves a
50
+ # slot within the splay interval.
51
+ do_splay = client_options . fetch ( :splay , Puppet [ :splay ] )
52
+ if do_splay
53
+ splay ( do_splay )
54
+
55
+ if disabled?
56
+ log_disabled_message
57
+ break
58
+ end
59
+ end
50
60
51
61
# waiting for certs may sleep for awhile depending on onetime, waitforcert and maxwaitforcert!
52
62
# this needs to happen before forking so that if we fail to obtain certs and try to exit, then
@@ -59,14 +69,19 @@ def run(client_options = {})
59
69
begin
60
70
# lock may sleep for awhile depending on waitforlock and maxwaitforlock!
61
71
lock do
62
- # NOTE: Timeout is pretty heinous as the location in which it
63
- # throws an error is entirely unpredictable, which means that
64
- # it can interrupt code blocks that perform cleanup or enforce
65
- # sanity. The only thing a Puppet agent should do after this
66
- # error is thrown is die with as much dignity as possible.
67
- Timeout . timeout ( Puppet [ :runtimeout ] , RunTimeoutError ) do
68
- Puppet . override ( ssl_context : ssl_context ) do
69
- client . run ( client_args )
72
+ if disabled?
73
+ log_disabled_message
74
+ nil
75
+ else
76
+ # NOTE: Timeout is pretty heinous as the location in which it
77
+ # throws an error is entirely unpredictable, which means that
78
+ # it can interrupt code blocks that perform cleanup or enforce
79
+ # sanity. The only thing a Puppet agent should do after this
80
+ # error is thrown is die with as much dignity as possible.
81
+ Timeout . timeout ( Puppet [ :runtimeout ] , RunTimeoutError ) do
82
+ Puppet . override ( ssl_context : ssl_context ) do
83
+ client . run ( client_args )
84
+ end
70
85
end
71
86
end
72
87
end
@@ -88,8 +103,7 @@ def run(client_options = {})
88
103
end
89
104
rescue RunTimeoutError => detail
90
105
Puppet . log_exception ( detail , _ ( "Execution of %{client_class} did not complete within %{runtimeout} seconds and was terminated." ) %
91
- { client_class : client_class ,
92
- runtimeout : Puppet [ :runtimeout ] } )
106
+ { client_class : client_class , runtimeout : Puppet [ :runtimeout ] } )
93
107
nil
94
108
rescue StandardError => detail
95
109
Puppet . log_exception ( detail , _ ( "Could not run %{client_class}: %{detail}" ) % { client_class : client_class , detail : detail } )
@@ -155,4 +169,8 @@ def wait_for_certificates(options)
155
169
sm = Puppet ::SSL ::StateMachine . new ( waitforcert : waitforcert , onetime : Puppet [ :onetime ] )
156
170
sm . ensure_client_certificate
157
171
end
172
+
173
+ def log_disabled_message
174
+ Puppet . notice _ ( "Skipping run of %{client_class}; administratively disabled (Reason: '%{disable_message}');\n Use 'puppet agent --enable' to re-enable." ) % { client_class : client_class , disable_message : disable_message }
175
+ end
158
176
end
0 commit comments