@@ -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,41 @@ 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 ! ( "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 ( ) ;
221
255
}
222
256
}
223
257
@@ -249,6 +283,7 @@ impl Rauc {
249
283
bb : & mut BrokerBuilder ,
250
284
wtb : & mut WatchedTasksBuilder ,
251
285
_conn : & Arc < Connection > ,
286
+ rauc_service : Service ,
252
287
) -> Result < Self > {
253
288
let inst = Self :: setup_topics ( bb) ;
254
289
@@ -263,6 +298,7 @@ impl Rauc {
263
298
inst. reload . clone ( ) ,
264
299
inst. enable_polling . clone ( ) ,
265
300
inst. channels . clone ( ) ,
301
+ rauc_service,
266
302
) ,
267
303
) ?;
268
304
@@ -274,6 +310,7 @@ impl Rauc {
274
310
bb : & mut BrokerBuilder ,
275
311
wtb : & mut WatchedTasksBuilder ,
276
312
conn : & Arc < Connection > ,
313
+ rauc_service : Service ,
277
314
) -> Result < Self > {
278
315
let inst = Self :: setup_topics ( bb) ;
279
316
@@ -469,6 +506,7 @@ impl Rauc {
469
506
inst. reload . clone ( ) ,
470
507
inst. enable_polling . clone ( ) ,
471
508
inst. channels . clone ( ) ,
509
+ rauc_service,
472
510
) ,
473
511
) ?;
474
512
0 commit comments