Skip to content

Commit 68547c9

Browse files
committed
dbus: rauc: reload rauc daemon if required
1 parent e2bdc3f commit 68547c9

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

src/dbus.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ impl DbusSession {
8989

9090
let conn = Arc::new(tacd.serve(conn_builder).build().await?);
9191

92+
let systemd = Systemd::new(bb, wtb, &conn).await?;
93+
9294
Ok(Self {
9395
hostname: Hostname::new(bb, wtb, &conn)?,
9496
network: Network::new(bb, wtb, &conn, led_dut, led_uplink)?,
95-
rauc: Rauc::new(bb, wtb, &conn)?,
96-
systemd: Systemd::new(bb, wtb, &conn).await?,
97+
rauc: Rauc::new(bb, wtb, &conn, systemd.rauc.clone())?,
98+
systemd,
9799
})
98100
}
99101
}

src/dbus/rauc.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ use anyhow::Result;
2121
use async_std::stream::StreamExt;
2222
use async_std::sync::Arc;
2323
use futures_util::FutureExt;
24-
use log::warn;
24+
use log::{info, warn};
2525
use serde::{Deserialize, Serialize};
2626

27+
use super::systemd::{Service, ServiceAction};
2728
use super::Connection;
2829
use crate::broker::{BrokerBuilder, Topic};
2930
use crate::watched_tasks::WatchedTasksBuilder;
@@ -188,6 +189,7 @@ async fn channel_list_update_task(
188189
reload: Arc<Topic<bool>>,
189190
enable_polling: Arc<Topic<bool>>,
190191
channels: Arc<Topic<Channels>>,
192+
rauc_service: Service,
191193
) -> Result<()> {
192194
let (reload_stream, _) = reload.subscribe_unbounded();
193195
let (mut enable_polling_stream, _) = enable_polling.subscribe_unbounded();
@@ -215,9 +217,41 @@ async fn channel_list_update_task(
215217
}
216218
};
217219

218-
update_system_conf(new_channels.primary(), enable_polling)?;
220+
let should_reload = update_system_conf(new_channels.primary(), enable_polling)?;
219221

220222
channels.set(new_channels);
223+
224+
if !should_reload {
225+
info!("Config is up to date. Will not reload.");
226+
continue;
227+
}
228+
229+
info!("New RAUC config written. Triggering deamon restart.");
230+
231+
let (mut status, status_subscription) = rauc_service.status.clone().subscribe_unbounded();
232+
rauc_service.action.set(ServiceAction::Restart);
233+
234+
info!("Waiting for deamon to go down");
235+
236+
while let Some(ev) = status.next().await {
237+
info!("Current status: {} ({})", ev.active_state, ev.sub_state);
238+
239+
if ev.active_state != "active" {
240+
break;
241+
}
242+
}
243+
244+
info!("Waiting for deamon to come up again");
245+
246+
while let Some(ev) = status.next().await {
247+
info!("Current status: {} ({})", ev.active_state, ev.sub_state);
248+
249+
if ev.active_state == "active" {
250+
break;
251+
}
252+
}
253+
254+
status_subscription.unsubscribe();
221255
}
222256
}
223257

@@ -249,6 +283,7 @@ impl Rauc {
249283
bb: &mut BrokerBuilder,
250284
wtb: &mut WatchedTasksBuilder,
251285
_conn: &Arc<Connection>,
286+
rauc_service: Service,
252287
) -> Result<Self> {
253288
let inst = Self::setup_topics(bb);
254289

@@ -263,6 +298,7 @@ impl Rauc {
263298
inst.reload.clone(),
264299
inst.enable_polling.clone(),
265300
inst.channels.clone(),
301+
rauc_service,
266302
),
267303
)?;
268304

@@ -274,6 +310,7 @@ impl Rauc {
274310
bb: &mut BrokerBuilder,
275311
wtb: &mut WatchedTasksBuilder,
276312
conn: &Arc<Connection>,
313+
rauc_service: Service,
277314
) -> Result<Self> {
278315
let inst = Self::setup_topics(bb);
279316

@@ -469,6 +506,7 @@ impl Rauc {
469506
inst.reload.clone(),
470507
inst.enable_polling.clone(),
471508
inst.channels.clone(),
509+
rauc_service,
472510
),
473511
)?;
474512

src/dbus/systemd.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub struct Systemd {
6666
pub labgrid: Service,
6767
#[allow(dead_code)]
6868
pub iobus: Service,
69-
#[allow(dead_code)]
7069
pub rauc: Service,
7170
}
7271

0 commit comments

Comments
 (0)