Skip to content

Commit c66ab05

Browse files
committed
Adjusted mission portal httpd.conf validation to show errors when they occur
Ticket: ENT-12653 Changelog: title (cherry picked from commit 141afd51f82517a3f10285b46c1db609d3cd9ff2)
1 parent d4158ef commit c66ab05

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

cfe_internal/enterprise/mission_portal.cf

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,19 @@ bundle agent mission_portal_apache_from_stage(config, staged_config)
284284
expression => returnszero("$(paths.systemctl) -q is-active cf-apache > /dev/null 2>&1", "useshell"),
285285
if => fileexists( $(paths.systemctl) );
286286

287+
"httpd_config_validated"
288+
expression => strcmp("$(validate_result[exit_code])", "0");
289+
"httpd_config_error"
290+
expression => not(strcmp("$(validate_result[exit_code])", "0"));
291+
287292
vars:
288293

289294
"validate_config"
290295
string => "$(sys.workdir)/httpd/bin/httpd -t -f $(staged_config)";
291296

297+
"validate_result"
298+
data => execresult_as_data("$(validate_config)", "useshell", "both");
299+
292300
# The location of the apache pid file moved from httpd/logs/httpd.pid to
293301
# httpd/httpd.pid in 3.15.5, 3.18.1 and, 3.19.0
294302

@@ -311,7 +319,7 @@ bundle agent mission_portal_apache_from_stage(config, staged_config)
311319
if => and( or( "apache_stop_after_new_staged_config_repaired",
312320
not( fileexists( "$(httpd_pid_file)" ) ),
313321
isnewerthan( $(config), $(staged_config) ) ),
314-
returnszero("$(validate_config) > /dev/null 2>&1 ", "useshell")),
322+
"httpd_config_validated"),
315323
classes => results("bundle", "mission_portal_apache_config"),
316324
comment => "We make sure that the deployed config is a copy of the staged
317325
config if the staged config passes a syntax check. We redirect
@@ -328,7 +336,7 @@ bundle agent mission_portal_apache_from_stage(config, staged_config)
328336
!systemd_supervised::
329337
"LD_LIBRARY_PATH=$(sys.workdir)/lib:$LD_LIBRARY_PATH $(sys.workdir)/httpd/bin/apachectl"
330338
args => "stop",
331-
if => and( returnszero("$(validate_config) > /dev/null 2>&1 ", "useshell"),
339+
if => and( "httpd_config_validated",
332340
isnewerthan( $(staged_config), $(config) ),
333341
fileexists( "$(httpd_pid_file)" ) ),
334342
contain => in_shell,
@@ -355,7 +363,8 @@ bundle agent mission_portal_apache_from_stage(config, staged_config)
355363
systemd_supervised::
356364
"cf-apache"
357365
service_policy => "stop",
358-
if => and( returnszero("$(validate_config) > /dev/null 2>&1 ", "useshell"),
366+
if => and( "httpd_config_validated",
367+
359368
isnewerthan( $(staged_config), $(config) ) ),
360369
classes => results( "bundle", "apache_stop_after_new_staged_config" ),
361370
comment => concat( "We have to stop apache before trying to start with a",
@@ -375,12 +384,14 @@ bundle agent mission_portal_apache_from_stage(config, staged_config)
375384
comment => "We restart apache after the new valid config is in place";
376385

377386
reports:
387+
httpd_config_error::
388+
"'$(staged_config)' failed to validate: $(validate_result[output])";
378389
DEBUG|DEBUG_mission_portal_apache_from_stage::
379390
"DEBUG $(this.bundle): '$(config)' should be a copy of '$(staged_config)' because it validates with '$(validate_config)'"
380-
if => returnszero("$(validate_config) > /dev/null 2>&1 ", "useshell");
391+
if => "httpd_config_validated";
381392

382393
"DEBUG $(this.bundle): '$(config)' should *not* be a copy of '$(staged_config)' because it failed to validate with '$(validate_config)'"
383-
if => not(returnszero("$(validate_config) > /dev/null 2>&1 ", "useshell"));
394+
if => not( "httpd_config_validated" );
384395
}
385396

386397
##################################################################

0 commit comments

Comments
 (0)