@@ -21,9 +21,10 @@ use anyhow::Result;
21
21
use async_std:: stream:: StreamExt ;
22
22
use async_std:: sync:: Arc ;
23
23
use futures_util:: FutureExt ;
24
- use log:: warn;
24
+ use log:: { info , warn} ;
25
25
use serde:: { Deserialize , Serialize } ;
26
26
27
+ use super :: systemd:: { Service , ServiceAction } ;
27
28
use super :: Connection ;
28
29
use crate :: broker:: { BrokerBuilder , Topic } ;
29
30
use crate :: watched_tasks:: WatchedTasksBuilder ;
@@ -188,6 +189,7 @@ async fn channel_list_update_task(
188
189
reload : Arc < Topic < bool > > ,
189
190
enable_polling : Arc < Topic < bool > > ,
190
191
channels : Arc < Topic < Channels > > ,
192
+ rauc_service : Service ,
191
193
) -> Result < ( ) > {
192
194
let ( reload_stream, _) = reload. subscribe_unbounded ( ) ;
193
195
let ( mut enable_polling_stream, _) = enable_polling. subscribe_unbounded ( ) ;
@@ -215,9 +217,43 @@ async fn channel_list_update_task(
215
217
}
216
218
} ;
217
219
218
- update_system_conf ( new_channels. primary ( ) , enable_polling) ?;
220
+ let should_reload = update_system_conf ( new_channels. primary ( ) , enable_polling) ?;
219
221
220
222
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
+ }
221
257
}
222
258
}
223
259
@@ -249,6 +285,7 @@ impl Rauc {
249
285
bb : & mut BrokerBuilder ,
250
286
wtb : & mut WatchedTasksBuilder ,
251
287
_conn : & Arc < Connection > ,
288
+ rauc_service : Service ,
252
289
) -> Result < Self > {
253
290
let inst = Self :: setup_topics ( bb) ;
254
291
@@ -263,6 +300,7 @@ impl Rauc {
263
300
inst. reload . clone ( ) ,
264
301
inst. enable_polling . clone ( ) ,
265
302
inst. channels . clone ( ) ,
303
+ rauc_service,
266
304
) ,
267
305
) ?;
268
306
@@ -274,6 +312,7 @@ impl Rauc {
274
312
bb : & mut BrokerBuilder ,
275
313
wtb : & mut WatchedTasksBuilder ,
276
314
conn : & Arc < Connection > ,
315
+ rauc_service : Service ,
277
316
) -> Result < Self > {
278
317
let inst = Self :: setup_topics ( bb) ;
279
318
@@ -469,6 +508,7 @@ impl Rauc {
469
508
inst. reload . clone ( ) ,
470
509
inst. enable_polling . clone ( ) ,
471
510
inst. channels . clone ( ) ,
511
+ rauc_service,
472
512
) ,
473
513
) ?;
474
514
0 commit comments