-
Notifications
You must be signed in to change notification settings - Fork 4
/
start.js
49 lines (40 loc) · 1.06 KB
/
start.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
48
49
const async = require('async');
const debug = require('debug')('ngineer:start');
const exec = require('child_process').exec;
const path = require('path');
const fs = require('fs');
const config = require('./config');
module.exports = function(ngineer, basePath, opts) {
function nginxStart(callback) {
config.command(basePath, function(err, command) {
if (err) {
return callback(err);
}
debug('running: ' + command);
exec(command, function(err) {
debug('started: ', err);
if (err) {
return callback(err);
}
callback();
});
});
}
return function(callback) {
let startTimeout;
function handleOnline() {
debug('detected nginx online');
clearTimeout(startTimeout);
callback();
}
// if already online do nothing
if (ngineer.online) {
return callback();
}
ngineer.once('online', handleOnline);
startTimeout = setTimeout(function() {
ngineer.removeListener('online', handleOnline);
nginxStart(callback);
}, 500);
};
};