Re-generate collectd and logrotate configs on container recreate

this was the reason graphs were not showing up properly
This commit is contained in:
Girish Ramakrishnan
2019-11-19 17:27:39 -08:00
parent d01749a2c2
commit bc314c1119
2 changed files with 19 additions and 43 deletions

View File

@@ -140,7 +140,15 @@ function createContainer(app, callback) {
docker.createContainer(app, function (error, container) {
if (error) return callback(error);
updateApp(app, { containerId: container.id }, callback);
updateApp(app, { containerId: container.id }, function (error) {
if (error) return callback(error);
// re-generate configs that rely on container id
async.series([
addLogrotateConfig.bind(null, app),
addCollectdProfile.bind(null, app)
], callback);
});
});
}
@@ -151,11 +159,15 @@ function deleteContainers(app, options, callback) {
debugApp(app, 'deleting app containers (app, scheduler)');
docker.deleteContainers(app.id, options, function (error) {
if (error) return callback(error);
updateApp(app, { containerId: null }, callback);
});
async.series([
// remove configs that rely on container id
unconfigureReverseProxy.bind(null, app),
removeCollectdProfile.bind(null, app),
removeLogrotateConfig.bind(null, app),
docker.stopContainers.bind(null, app.id),
docker.deleteContainers.bind(null, app.id, options),
updateApp.bind(null, app, { containerId: null })
], callback);
}
function createAppDir(app, callback) {
@@ -519,10 +531,6 @@ function install(app, args, progressCallback, callback) {
// teardown for re-installs
progressCallback.bind(null, { percent: 10, message: 'Cleaning up old install' }),
unconfigureReverseProxy.bind(null, app),
removeCollectdProfile.bind(null, app),
removeLogrotateConfig.bind(null, app),
docker.stopContainers.bind(null, app.id),
deleteContainers.bind(null, app, { managedOnly: true }),
function teardownAddons(next) {
// when restoring, app does not require these addons anymore. remove carefully to preserve the db passwords
@@ -580,12 +588,6 @@ function install(app, args, progressCallback, callback) {
progressCallback.bind(null, { percent: 70, message: 'Creating container' }),
createContainer.bind(null, app),
progressCallback.bind(null, { percent: 75, message: 'Setting up logrotate config' }),
addLogrotateConfig.bind(null, app),
progressCallback.bind(null, { percent: 80, message: 'Setting up collectd profile' }),
addCollectdProfile.bind(null, app),
startApp.bind(null, app),
progressCallback.bind(null, { percent: 85, message: 'Waiting for DNS propagation' }),
@@ -637,7 +639,6 @@ function create(app, args, progressCallback, callback) {
async.series([
progressCallback.bind(null, { percent: 10, message: 'Cleaning up old install' }),
docker.stopContainers.bind(null, app.id),
deleteContainers.bind(null, app, { managedOnly: true }),
// FIXME: re-setup addons only because sendmail addon to re-inject env vars on mailboxName change
@@ -672,8 +673,6 @@ function changeLocation(app, args, progressCallback, callback) {
async.series([
progressCallback.bind(null, { percent: 10, message: 'Cleaning up old install' }),
unconfigureReverseProxy.bind(null, app),
docker.stopContainers.bind(null, app.id),
deleteContainers.bind(null, app, { managedOnly: true }),
function (next) {
let obsoleteDomains = oldConfig.alternateDomains.filter(function (o) {
@@ -727,7 +726,6 @@ function migrateDataDir(app, args, progressCallback, callback) {
async.series([
progressCallback.bind(null, { percent: 10, message: 'Cleaning up old install' }),
docker.stopContainers.bind(null, app.id),
deleteContainers.bind(null, app, { managedOnly: true }),
progressCallback.bind(null, { percent: 45, message: 'Ensuring app data directory' }),
@@ -774,10 +772,6 @@ function configure(app, args, progressCallback, callback) {
async.series([
progressCallback.bind(null, { percent: 10, message: 'Cleaning up old install' }),
unconfigureReverseProxy.bind(null, app),
removeCollectdProfile.bind(null, app),
removeLogrotateConfig.bind(null, app),
docker.stopContainers.bind(null, app.id),
deleteContainers.bind(null, app, { managedOnly: true }),
function (next) {
if (!oldConfig) return next();
@@ -814,12 +808,6 @@ function configure(app, args, progressCallback, callback) {
progressCallback.bind(null, { percent: 60, message: 'Creating container' }),
createContainer.bind(null, app),
progressCallback.bind(null, { percent: 65, message: 'Setting up logrotate config' }),
addLogrotateConfig.bind(null, app),
progressCallback.bind(null, { percent: 70, message: 'Add collectd profile' }),
addCollectdProfile.bind(null, app),
startApp.bind(null, app),
progressCallback.bind(null, { percent: 80, message: 'Waiting for DNS propagation' }),
@@ -882,7 +870,6 @@ function update(app, args, progressCallback, callback) {
// note: we cleanup first and then backup. this is done so that the app is not running should backup fail
// we cannot easily 'recover' from backup failures because we have to revert manfest and portBindings
progressCallback.bind(null, { percent: 35, message: 'Cleaning up old install' }),
docker.stopContainers.bind(null, app.id),
deleteContainers.bind(null, app, { managedOnly: true }),
function deleteImageIfChanged(done) {
if (app.manifest.dockerImage === updateConfig.manifest.dockerImage) return done();
@@ -991,15 +978,6 @@ function uninstall(app, args, progressCallback, callback) {
assert.strictEqual(typeof callback, 'function');
async.series([
progressCallback.bind(null, { percent: 0, message: 'Remove collectd profile' }),
removeCollectdProfile.bind(null, app),
progressCallback.bind(null, { percent: 5, message: 'Remove logrotate config' }),
removeLogrotateConfig.bind(null, app),
progressCallback.bind(null, { percent: 10, message: 'Stopping app' }),
docker.stopContainers.bind(null, app.id),
progressCallback.bind(null, { percent: 20, message: 'Deleting container' }),
deleteContainers.bind(null, app, {}),
@@ -1018,9 +996,6 @@ function uninstall(app, args, progressCallback, callback) {
progressCallback.bind(null, { percent: 70, message: 'Cleanup icon' }),
removeIcon.bind(null, app),
progressCallback.bind(null, { percent: 80, message: 'Unconfiguring reverse proxy' }),
unconfigureReverseProxy.bind(null, app),
progressCallback.bind(null, { percent: 90, message: 'Cleanup logs' }),
cleanupLogs.bind(null, app),