Skip to content
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

Fix service exit (mySQL) #92

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
52 changes: 52 additions & 0 deletions src/services/azure-sql-server/azure-sql-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,58 @@ function runExec(container) {
previousKey = key;
});

docker.getEvents({}, function (err, evtSource) {
evtSource.on("data", function (data) {

let dockerEventState = null;
JosephSemrai marked this conversation as resolved.
Show resolved Hide resolved

try {
dockerEventState = JSON.parse(data);

if (dockerEventState.Actor.Attributes.execID === exec.id && dockerEventState.status === "exec_die") {

// Manually tries to shut mysqld down
var options = {
Cmd: ['bash', '-c', 'mysqld stop'],
AttachStdout: true,
AttachStderr: true
};

container.exec(options, function(err, exec) {
if (err) return;
exec.start(function(err, stream) {
if (err) return;

container.modem.demuxStream(stream, process.stdout, process.stderr);
JosephSemrai marked this conversation as resolved.
Show resolved Hide resolved

exec.inspect(function(err, data) {
if (err) return;
});
});
});

// Stop will send SIGKILL to mysqld, causing it to shut down. We can then gracefully exit the process.
container.stop().then(function() {
process.exit(0)
})
JosephSemrai marked this conversation as resolved.
Show resolved Hide resolved

}
} catch (exception) { // Catches exception caused by malformatted JSON emitted by healthchecker
console.error(exception)
JosephSemrai marked this conversation as resolved.
Show resolved Hide resolved
}

});
});










container.wait(function(err, data) {
exit(stream, isRaw);
});
Expand Down