@@ -25,6 +25,8 @@ const internalNginx = {
25
25
* @returns {Promise }
26
26
*/
27
27
configure : ( model , host_type , host ) => {
28
+ let combined_meta = { } ;
29
+
28
30
return internalNginx . test ( )
29
31
. then ( ( ) => {
30
32
// Nginx is OK
@@ -39,30 +41,46 @@ const internalNginx = {
39
41
return internalNginx . test ( )
40
42
. then ( ( ) => {
41
43
// nginx is ok
44
+ combined_meta = _ . assign ( { } , host . meta , {
45
+ nginx_online : true ,
46
+ nginx_err : null
47
+ } ) ;
48
+
42
49
return model
43
50
. query ( )
44
51
. where ( 'id' , host . id )
45
52
. patch ( {
46
- meta : _ . assign ( { } , host . meta , {
47
- nginx_online : true ,
48
- nginx_err : null
49
- } )
53
+ meta : combined_meta
50
54
} ) ;
51
55
} )
52
56
. catch ( err => {
57
+ // Remove the error_log line because it's a docker-ism false positive that doesn't need to be reported.
58
+ // It will always look like this:
59
+ // nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (6: No such device or address)
60
+
61
+ let valid_lines = [ ] ;
62
+ let err_lines = err . message . split ( "\n" ) ;
63
+ err_lines . map ( function ( line ) {
64
+ if ( line . indexOf ( '/var/log/nginx/error.log' ) === - 1 ) {
65
+ valid_lines . push ( line ) ;
66
+ }
67
+ } ) ;
68
+
53
69
if ( debug_mode ) {
54
- logger . error ( 'Nginx test failed:' , err . message ) ;
70
+ logger . error ( 'Nginx test failed:' , valid_lines . join ( "\n" ) ) ;
55
71
}
56
72
57
73
// config is bad, update meta and delete config
74
+ combined_meta = _ . assign ( { } , host . meta , {
75
+ nginx_online : false ,
76
+ nginx_err : valid_lines . join ( "\n" )
77
+ } ) ;
78
+
58
79
return model
59
80
. query ( )
60
81
. where ( 'id' , host . id )
61
82
. patch ( {
62
- meta : _ . assign ( { } , host . meta , {
63
- nginx_online : false ,
64
- nginx_err : err . message
65
- } )
83
+ meta : combined_meta
66
84
} )
67
85
. then ( ( ) => {
68
86
return internalNginx . deleteConfig ( host_type , host , true ) ;
@@ -71,7 +89,10 @@ const internalNginx = {
71
89
} )
72
90
. then ( ( ) => {
73
91
return internalNginx . reload ( ) ;
74
- } ) ;
92
+ } )
93
+ . then ( ( ) => {
94
+ return combined_meta ;
95
+ } )
75
96
} ,
76
97
77
98
/**
@@ -82,7 +103,7 @@ const internalNginx = {
82
103
logger . info ( 'Testing Nginx configuration' ) ;
83
104
}
84
105
85
- return utils . exec ( '/usr/sbin/nginx -t' ) ;
106
+ return utils . exec ( '/usr/sbin/nginx -t -g "error_log off;" ' ) ;
86
107
} ,
87
108
88
109
/**
0 commit comments