Skip to content

Commit 49ad780

Browse files
committed
dbus: rauc: add enable_auto_install
1 parent 1b1e735 commit 49ad780

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

@@ -302,6 +310,14 @@ impl Rauc {
302310
Some(false),
303311
1,
304312
),
313+
enable_auto_install: bb.topic(
314+
"/v1/tac/update/enable_auto_install",
315+
true,
316+
true,
317+
true,
318+
Some(false),
319+
1,
320+
),
305321
}
306322
}
307323

@@ -325,6 +341,7 @@ impl Rauc {
325341
Arc::new(Connection),
326342
inst.reload.clone(),
327343
inst.enable_polling.clone(),
344+
inst.enable_auto_install.clone(),
328345
inst.channels.clone(),
329346
rauc_service,
330347
),
@@ -593,6 +610,7 @@ impl Rauc {
593610
conn.clone(),
594611
inst.reload.clone(),
595612
inst.enable_polling.clone(),
613+
inst.enable_auto_install.clone(),
596614
inst.channels.clone(),
597615
rauc_service,
598616
),

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)