Fixed standalone server closing, and made the index.js promise resolve only after the standalone server has closed.

This commit is contained in:
Vasil Rangelov 2017-05-17 18:20:36 +03:00
parent 248640cd3e
commit e073b273b3
2 changed files with 28 additions and 10 deletions

View File

@ -84,13 +84,13 @@ module.exports.run = function (args) {
if (servers) {
if (args.tlsSni01Port) {
servers = servers.startServers(
servers.startServers(
[], args.tlsSni01Port
, { debug: args.debug, httpsOptions: le.httpsOptions }
);
}
else {
servers = servers.startServers(
servers.startServers(
args.http01Port || [80], []
, { debug: args.debug }
);
@ -117,10 +117,6 @@ module.exports.run = function (args) {
console.log("Renewing them now");
return certs._renewing;
}).then(function (certs) {
if (servers) {
servers.closeServers();
}
console.log("");
console.log("Got certificate(s) for " + certs.altnames.join(', '));
console.log("\tIssued at " + new Date(certs.issuedAt).toISOString() + "");
@ -147,6 +143,12 @@ module.exports.run = function (args) {
);
console.log("");
if (servers) {
return servers.closeServers({ debug: args.debug }).then(function() {
return 0;
});
}
return 0;
}, function (err) {
console.error('[Error]: greenlock-cli');

View File

@ -77,11 +77,27 @@ module.exports.create = function (challenge) {
}
, closeServers: function () {
servers._servers.forEach(function (server) {
server.close();
, closeServers: function (opts) {
opts = opts || {};
return new Promise(function (done) {
var closedServers = 0;
var serversToClose = servers._servers.length;
if (0 === serversToClose) {
done();
}
servers._servers.forEach(function (server) {
server.close(function () {
if (serversToClose === ++closedServers) {
if (opts.debug) {
console.info('Closed all servers');
}
servers._servers = [];
done();
}
});
});
});
servers._servers = [];
}
};