-
Notifications
You must be signed in to change notification settings - Fork 5
/
test-nginx.js
executable file
·47 lines (30 loc) · 1.09 KB
/
test-nginx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env node
var WITH_NGINX_TEST = true;
var nginx_config_parser = require('./lib/nginx_config_parser'),
fs = require('fs'),
spawn = require('child_process').spawn,
path = require('path');
var nginxConfLocation = {
"test": './test-conf.conf',
"real": '/usr/local/nginx/conf/nginx.conf'
}[ WITH_NGINX_TEST ? "real" : "test" ];
var confDir = '/usr/local/nginx/conf/';
var conf = nginx_config_parser.parse( fs.readFileSync(nginxConfLocation, 'utf-8') );
var sameThing = nginx_config_parser.stringify(conf);
console.log(JSON.stringify(conf, null, 4));
return;
if (WITH_NGINX_TEST) {
fs.writeFileSync( path.join(confDir, 'my-nginx.conf'), sameThing);
var nginxConfTest = spawn('sudo', ['nginx', '-c', path.join(confDir, 'my-nginx.conf')]);
nginxConfTest.stdout.on('data', function (data) {
console.log('nginx stdout: ' + data);
});
nginxConfTest.stderr.on('data', function (data) {
console.log('nginx stderr: ' + data);
});
nginxConfTest.on('close', function (code) {
console.log('nginx conf test exited with code ' + code);
});
} else {
console.log( sameThing );
}