Skip to content

Commit fae4281

Browse files
committed
dbus: rauc: add support for enabling the auto install feature
Automatic installation and boot of updates can be useful when managing a fleet of devices. This is however a feature that requires strict user consent, hence why it is off by default. Add backend-support for enabling this feature. Frontent support in the web interface will be added later. We always enable auto-reboot together with auto-install, since the migration scripts only run once at the end of the installation. A system that is updated, but not rebooted, would thus accumulate changes that are not migrated to the other slot. Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
1 parent c21f5cc commit fae4281

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,21 @@ paths:
775775
'400':
776776
description: The value could not be parsed as boolean
777777

778+
/v1/tac/update/enable_auto_install:
779+
put:
780+
summary: Enable automatic installation of operating system updates
781+
tags: [Updating]
782+
requestBody:
783+
content:
784+
application/json:
785+
schema:
786+
type: boolean
787+
responses:
788+
'204':
789+
description: Automatic installation of updates was enabled/disabled
790+
'400':
791+
description: The value could not be parsed as boolean
792+
778793
/v1/tac/update/operation:
779794
get:
780795
summary: Get the currently running system update operation

src/dbus/rauc.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub struct Rauc {
140140
pub reload: Arc<Topic<bool>>,
141141
pub should_reboot: Arc<Topic<bool>>,
142142
pub enable_polling: Arc<Topic<bool>>,
143+
pub enable_auto_install: Arc<Topic<bool>>,
143144
}
144145

145146
#[cfg(not(feature = "demo_mode"))]
@@ -205,15 +206,18 @@ async fn channel_list_update_task(
205206
conn: Arc<Connection>,
206207
reload: Arc<Topic<bool>>,
207208
enable_polling: Arc<Topic<bool>>,
209+
enable_auto_install: Arc<Topic<bool>>,
208210
channels: Arc<Topic<Channels>>,
209211
rauc_service: Service,
210212
) -> Result<()> {
211213
let poller = PollerProxy::new(&conn).await.unwrap();
212214

213215
let (reload_stream, _) = reload.subscribe_unbounded();
214216
let (mut enable_polling_stream, _) = enable_polling.subscribe_unbounded();
217+
let (mut enable_auto_install_stream, _) = enable_auto_install.subscribe_unbounded();
215218

216219
let mut enable_polling = enable_polling_stream.next().await.unwrap_or(false);
220+
let mut enable_auto_install = enable_auto_install_stream.next().await.unwrap_or(false);
217221

218222
'reload_loop: loop {
219223
futures::select! {
@@ -225,6 +229,9 @@ async fn channel_list_update_task(
225229
enable_polling_new = enable_polling_stream.recv().fuse() => {
226230
enable_polling = enable_polling_new?;
227231
}
232+
enable_auto_install_new = enable_auto_install_stream.recv().fuse() => {
233+
enable_auto_install = enable_auto_install_new?;
234+
}
228235
};
229236

230237
// Read the list of available update channels
@@ -236,7 +243,8 @@ async fn channel_list_update_task(
236243
}
237244
};
238245

239-
let should_reload = update_system_conf(new_channels.primary(), enable_polling)?;
246+
let should_reload =
247+
update_system_conf(new_channels.primary(), enable_polling, enable_auto_install)?;
240248

241249
channels.set(new_channels);
242250

@@ -304,6 +312,14 @@ impl Rauc {
304312
Some(false),
305313
1,
306314
),
315+
enable_auto_install: bb.topic(
316+
"/v1/tac/update/enable_auto_install",
317+
true,
318+
true,
319+
true,
320+
Some(false),
321+
1,
322+
),
307323
}
308324
}
309325

@@ -327,6 +343,7 @@ impl Rauc {
327343
Arc::new(Connection),
328344
inst.reload.clone(),
329345
inst.enable_polling.clone(),
346+
inst.enable_auto_install.clone(),
330347
inst.channels.clone(),
331348
rauc_service,
332349
),
@@ -595,6 +612,7 @@ impl Rauc {
595612
conn.clone(),
596613
inst.reload.clone(),
597614
inst.enable_polling.clone(),
615+
inst.enable_auto_install.clone(),
598616
inst.channels.clone(),
599617
rauc_service,
600618
),

src/dbus/rauc/system_conf.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const MAGIC_LINE: &str = "\n# <tacd-poll-section>\n";
2626
fn poll_section(
2727
primary_channel: Option<&Channel>,
2828
polling: bool,
29+
auto_install: bool,
2930
) -> Result<Option<String>, std::fmt::Error> {
3031
// If no primary channel is configured or if polling is not enabled,
3132
// then we do not need a `[poll]` section at all.
@@ -46,15 +47,25 @@ fn poll_section(
4647

4748
writeln!(&mut section, "candidate-criteria=different-version")?;
4849

50+
if auto_install {
51+
writeln!(&mut section, "install-criteria=different-version")?;
52+
writeln!(
53+
&mut section,
54+
"reboot-criteria=updated-slots;updated-artifacts"
55+
)?;
56+
writeln!(&mut section, "reboot-cmd=systemctl reboot")?;
57+
}
58+
4959
Ok(Some(section))
5060
}
5161

5262
pub fn update_system_conf(
5363
primary_channel: Option<&Channel>,
5464
enable_polling: bool,
65+
enable_auto_install: bool,
5566
) -> std::io::Result<bool> {
5667
let dynamic_conf = {
57-
match poll_section(primary_channel, enable_polling) {
68+
match poll_section(primary_channel, enable_polling, enable_auto_install) {
5869
Ok(Some(ps)) => {
5970
// We use the config in /etc as a template ...
6071
let static_conf = read_to_string(STATIC_CONF_PATH)?;

0 commit comments

Comments
 (0)