restart apps on addon container change

when the IP changes on addon container re-create, the apps don't
detect this (maybe there is some large DNS cache timeout in docker)
This commit is contained in:
Girish Ramakrishnan
2020-05-22 16:43:16 -07:00
parent 90c24cf356
commit 7efb57c8da
2 changed files with 43 additions and 2 deletions

View File

@@ -58,6 +58,7 @@ exports = module.exports = {
restoreInstalledApps: restoreInstalledApps,
configureInstalledApps: configureInstalledApps,
schedulePendingTasks: schedulePendingTasks,
restartAppsUsingAddons: restartAppsUsingAddons,
getDataDir: getDataDir,
getIconPath: getIconPath,
@@ -1986,6 +1987,34 @@ function configureInstalledApps(callback) {
});
}
function restartAppsUsingAddons(changedAddons, callback) {
assert(Array.isArray(changedAddons));
assert.strictEqual(typeof callback, 'function');
getAll(function (error, apps) {
if (error) return callback(error);
apps = apps.filter(app => app.manifest.addons && _.intersection(Object.keys(app.manifest.addons), changedAddons).length !== 0);
apps = apps.filter(app => app.installationState !== exports.ISTATE_ERROR); // remove errored apps. let them be 'repaired' by hand
apps = apps.filter(app => app.installationState !== exports.ISTATE_PENDING_RESTART); // safeguard against tasks being created non-stop restart if we crash on startup
async.eachSeries(apps, function (app, iteratorDone) {
debug(`restartAppsUsingAddons: marking ${app.fqdn} for restart`);
const task = {
args: {},
values: { runState: exports.RSTATE_RUNNING }
};
addTask(app.id, exports.ISTATE_PENDING_RESTART, task, function (error, result) {
if (error) debug(`restartAppsUsingAddons: error marking ${app.fqdn} for restart: ${JSON.stringify(error)}`);
else debug(`restartAppsUsingAddons: marked ${app.id} for restart with taskId ${result.taskId}`);
iteratorDone(); // ignore error
});
}, callback);
});
}
// auto-restart app tasks after a crash
function schedulePendingTasks(callback) {
assert.strictEqual(typeof callback, 'function');