Skip to content

Commit c71040c

Browse files
committed
dbus: rauc: reload rauc daemon when required
This uses the existing systemd DBus API integration to trigger a daemon restart (there is no support to just reload the config as of now) and keep track of the following state changes. Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
1 parent a054af6 commit c71040c

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-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: 42 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,43 @@ 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!("New RAUC config written. Triggering daemon restart.");
226+
227+
let (mut status, status_subscription) =
228+
rauc_service.status.clone().subscribe_unbounded();
229+
rauc_service.action.set(ServiceAction::Restart);
230+
231+
info!("Waiting for daemon to go down");
232+
233+
while let Some(ev) = status.next().await {
234+
info!("Current status: {} ({})", ev.active_state, ev.sub_state);
235+
236+
if ev.active_state != "active" {
237+
break;
238+
}
239+
}
240+
241+
info!("Waiting for daemon to come up again");
242+
243+
while let Some(ev) = status.next().await {
244+
info!("Current status: {} ({})", ev.active_state, ev.sub_state);
245+
246+
if ev.active_state == "active" {
247+
break;
248+
}
249+
}
250+
251+
info!("Done");
252+
253+
status_subscription.unsubscribe();
254+
} else {
255+
info!("Config is up to date. Will not reload.");
256+
}
221257
}
222258
}
223259

@@ -249,6 +285,7 @@ impl Rauc {
249285
bb: &mut BrokerBuilder,
250286
wtb: &mut WatchedTasksBuilder,
251287
_conn: &Arc<Connection>,
288+
rauc_service: Service,
252289
) -> Result<Self> {
253290
let inst = Self::setup_topics(bb);
254291

@@ -263,6 +300,7 @@ impl Rauc {
263300
inst.reload.clone(),
264301
inst.enable_polling.clone(),
265302
inst.channels.clone(),
303+
rauc_service,
266304
),
267305
)?;
268306

@@ -274,6 +312,7 @@ impl Rauc {
274312
bb: &mut BrokerBuilder,
275313
wtb: &mut WatchedTasksBuilder,
276314
conn: &Arc<Connection>,
315+
rauc_service: Service,
277316
) -> Result<Self> {
278317
let inst = Self::setup_topics(bb);
279318

@@ -469,6 +508,7 @@ impl Rauc {
469508
inst.reload.clone(),
470509
inst.enable_polling.clone(),
471510
inst.channels.clone(),
511+
rauc_service,
472512
),
473513
)?;
474514

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)