Skip to content

Fix config verification and reload error handling #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ Orchestrator.prototype.start = function start(fn) {
mkdirp.sync(pidDir);
} catch (e) { return fn(e); }

return this.verify(function verified(err) {
return this.verify(function verified(err, verified) {
if (err) return fn(err);
if (!verified) return fn(new Error('Invalid config'));

this.run('haproxy -D -f %s -p %s', this.config, this.pidFile, function ran(err, res, cmd) {
//
Expand Down Expand Up @@ -210,13 +211,14 @@ Orchestrator.prototype.reload = function reload(hard, fn) {
var cmd = 'haproxy -D -f %s -p %s -sf %s';
if (hard) cmd = 'haproxy -D -f %s -p %s -st %s';

return this.verify(function verified(err) {
return this.verify(function verified(err, verified) {
if (err) return fn(err);
if (!verified) return fn(new Error('Invalid config'))

var current = this.pid;

this.run(cmd, this.config, this.pidFile, current, function ran(err, res, cmd) {
if (err) return fn(err);
if (err && !err.stderr) return fn(err, undef, cmd);

//
// Poll for the change of pid.
Expand All @@ -243,7 +245,7 @@ Orchestrator.prototype.verify = function verify(fn) {
fn = fn.bind(this);

return this.run('haproxy -c -f %s', this.config, function verified(err, res, cmd) {
fn(undefined, !err && !!res, cmd);
fn(undefined, !(err && !err.stderr), cmd);
});
};

Expand Down