diff options
author | Albin Suresh <albin.suresh@softwareag.com> | 2021-08-30 17:35:01 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 17:35:01 +0530 |
commit | 99c532af3b6cee43b59b0ad5d000e8b807b8eba3 (patch) | |
tree | 41993dd4e9ca243b1616fb71b2241b98a44eaa4c | |
parent | dbca35fc2318b3a78a2cb76471aa0e37c941ce33 (diff) |
[CIT-532] Subscribe to cloud operations only after device creation (#404)
* [CIT-532] Subscribe to cloud operations only after device creation
-rw-r--r-- | tedge/src/cli/connect/command.rs | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/tedge/src/cli/connect/command.rs b/tedge/src/cli/connect/command.rs index 2360fbe5..96d887ce 100644 --- a/tedge/src/cli/connect/command.rs +++ b/tedge/src/cli/connect/command.rs @@ -95,6 +95,17 @@ impl Command for ConnectCommand { ); } + if let Cloud::C8y = self.cloud { + println!("Restarting mosquitto to resubscribe to bridged inbound cloud topics after device creation"); + restart_mosquitto( + &bridge_config, + self.service_manager.as_ref(), + &self.config_location, + )?; + + enable_software_management(&bridge_config, self.service_manager.as_ref()); + } + Ok(()) } } @@ -306,11 +317,7 @@ fn new_bridge( return Err(err); } - println!("Restarting mosquitto service.\n"); - if let Err(err) = service_manager.restart_service(SystemService::Mosquitto) { - clean_up(config_location, bridge_config)?; - return Err(err.into()); - } + restart_mosquitto(bridge_config, service_manager, config_location)?; println!( "Awaiting mosquitto to start. This may take up to {} seconds.\n", @@ -320,7 +327,7 @@ fn new_bridge( MOSQUITTO_RESTART_TIMEOUT_SECONDS, )); - println!("Persisting mosquitto on reboot.\n"); + println!("Enabling mosquitto service on reboots.\n"); if let Err(err) = service_manager.enable_service(SystemService::Mosquitto) { clean_up(config_location, bridge_config)?; return Err(err.into()); @@ -339,6 +346,28 @@ fn new_bridge( } } + Ok(()) +} + +fn restart_mosquitto( + bridge_config: &BridgeConfig, + service_manager: &dyn SystemServiceManager, + config_location: &TEdgeConfigLocation, +) -> Result<(), ConnectError> { + println!("Restarting mosquitto service.\n"); + if let Err(err) = service_manager.restart_service(SystemService::Mosquitto) { + clean_up(config_location, bridge_config)?; + return Err(err.into()); + } + + Ok(()) +} + +fn enable_software_management( + bridge_config: &BridgeConfig, + service_manager: &dyn SystemServiceManager, +) { + println!("Enabling software management.\n"); if bridge_config.use_agent { println!("Checking if tedge-agent is installed.\n"); if which("tedge_agent").is_ok() { @@ -350,10 +379,7 @@ fn new_bridge( println!("Info: Software management is not installed. So, skipping enabling related components.\n"); } } - - Ok(()) } - // To preserve error chain and not discard other errors we need to ignore error here // (don't use '?' with the call to this function to preserve original error). fn clean_up( |