Skip to content

Commit e0074a2

Browse files
authored
Merge pull request #401 from foundriesio/finalize-what-was-installed-v94
api: Don't start newly enabled apps during finalization
2 parents 1d45a64 + a26ef85 commit e0074a2

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/api.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,19 @@ class LiteInstall : public InstallContext {
591591
return InstallResult{InstallResult::Status::DownloadFailed, ""};
592592
}
593593

594+
// Update the target's custom data with a list of apps considered for an update taking into account
595+
// the target's app list and the current .toml configuration.
596+
auto custom{target_->custom_data()};
597+
Json::Value app_list_json;
598+
for (const auto& app :
599+
ComposeAppManager::getRequiredApps(ComposeAppManager::Config(client_->config.pacman), *target_)) {
600+
app_list_json[app.first] = app.second;
601+
}
602+
if (!app_list_json.empty()) {
603+
custom["install-context"]["apps"] = app_list_json;
604+
}
605+
target_->updateCustom(custom);
606+
594607
auto rc = client_->install(*target_, mode_);
595608
auto status = InstallResult::Status::Failed;
596609
if (rc == data::ResultCode::Numeric::kNeedCompletion) {

src/composeappmanager.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,26 @@ data::InstallationResult ComposeAppManager::finalizeInstall(const Uptane::Target
461461
} else {
462462
LOG_INFO << "Installing and starting Apps...";
463463
}
464+
465+
const auto install_context{target.custom_data().get("install-context", Json::nullValue)};
466+
std::string newly_enabled_apps_msg;
464467
// "finalize" (run) Apps that were pulled and created before reboot
465468
for (const auto& app_pair : getApps(target)) {
469+
if (!install_context.empty() && install_context.isMember("apps")) {
470+
if (!(install_context["apps"].isMember(app_pair.first) &&
471+
install_context["apps"][app_pair.first] == app_pair.second)) {
472+
LOG_INFO << app_pair.first
473+
<< " was enabled after the update reboot; skipping its start during finalization."
474+
" Re-run the update to fetch and install the newly enabled apps.";
475+
if (!newly_enabled_apps_msg.empty()) {
476+
newly_enabled_apps_msg += ", " + app_pair.first;
477+
} else {
478+
newly_enabled_apps_msg = "\n# Newly enabled apps are detected: " + app_pair.first;
479+
}
480+
continue;
481+
}
482+
}
483+
466484
const AppEngine::Result run_res = app_engine_->run({app_pair.first, app_pair.second});
467485
if (!run_res) {
468486
const std::string err_desc{boost::str(
@@ -473,6 +491,7 @@ data::InstallationResult ComposeAppManager::finalizeInstall(const Uptane::Target
473491
// Do we need to set some flag for the uboot and trigger a system reboot in order to boot on a previous
474492
// ostree version, hence a proper/full rollback happens???
475493
ir.description += ", however " + err_desc;
494+
ir.description += newly_enabled_apps_msg;
476495
ir.description += "\n# Apps running:\n" + getRunningAppsInfoForReport();
477496
// this is a hack to distinguish between ostree install (rollback) and App start failures.
478497
// data::ResultCode::Numeric::kInstallFailed - boot on a new ostree version failed (rollback at boot)
@@ -494,6 +513,9 @@ data::InstallationResult ComposeAppManager::finalizeInstall(const Uptane::Target
494513

495514
app_engine_->prune(app_shortlist);
496515
}
516+
if (!newly_enabled_apps_msg.empty()) {
517+
ir.description += newly_enabled_apps_msg;
518+
}
497519
}
498520

499521
if (data::ResultCode::Numeric::kNeedCompletion != ir.result_code.num_code) {

src/main.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <boost/program_options.hpp>
1313

1414
#include "aktualizr-lite/cli/cli.h"
15+
#include "composeappmanager.h"
1516
#include "crypto/keymanager.h"
1617
#include "helpers.h"
1718
#include "http/httpclient.h"
@@ -206,6 +207,18 @@ static std::tuple<data::ResultCode::Numeric, DownloadResultWithStat, std::string
206207
return {res.result_code.num_code, download_res, target.correlation_id()};
207208
}
208209

210+
// Update the target's custom data with a list of apps considered for an update taking into account
211+
// the target's app list and the current .toml configuration.
212+
auto custom{target.custom_data()};
213+
Json::Value app_list_json;
214+
for (const auto& app : ComposeAppManager::getRequiredApps(ComposeAppManager::Config(client.config.pacman), target)) {
215+
app_list_json[app.first] = app.second;
216+
}
217+
if (!app_list_json.empty()) {
218+
custom["install-context"]["apps"] = app_list_json;
219+
}
220+
target.updateCustom(custom);
221+
209222
return {client.install(target), download_res, target.correlation_id()};
210223
}
211224

0 commit comments

Comments
 (0)