diff options
author | PradeepKiruvale <pradeepkumar.kj@softwareag.com> | 2022-03-24 13:35:38 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-24 13:35:38 +0530 |
commit | 59142ef60484ddc7b103c841d34b308b9444f316 (patch) | |
tree | d7b8f89179d2244a1e116081b11a28e7c3a141fa /crates/core/tedge_agent/src | |
parent | d9ca6aedfad3de7931964200f26e40fdd577b48a (diff) |
[#761] tedge init (#993)
* tedge init #Closes 761
* add file/directory creation errors
* add the clear session to az and collectd mappers
* refactor tedgecomponent
* remove redundant code
* subscribe to az/collectd topics in init_session
* remove duplicate init_sessions
Diffstat (limited to 'crates/core/tedge_agent/src')
-rw-r--r-- | crates/core/tedge_agent/src/agent.rs | 11 | ||||
-rw-r--r-- | crates/core/tedge_agent/src/main.rs | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/crates/core/tedge_agent/src/agent.rs b/crates/core/tedge_agent/src/agent.rs index 4a7e3667..00c1c71a 100644 --- a/crates/core/tedge_agent/src/agent.rs +++ b/crates/core/tedge_agent/src/agent.rs @@ -21,6 +21,7 @@ use tedge_config::{ MqttBindAddressSetting, MqttPortSetting, RunPathDefaultSetting, SoftwarePluginDefaultSetting, TEdgeConfigLocation, TmpPathDefaultSetting, DEFAULT_LOG_PATH, DEFAULT_RUN_PATH, }; +use tedge_utils::file::create_directory_with_user_group; use tokio::sync::Mutex; use tracing::{debug, error, info, instrument, warn}; @@ -209,9 +210,17 @@ impl SmAgent { } #[instrument(skip(self), name = "sm-agent")] - pub async fn init_session(&mut self) -> Result<(), AgentError> { + pub async fn init(&mut self) -> Result<(), anyhow::Error> { + create_directory_with_user_group("/etc/tedge/.agent", "tedge-agent", "tedge-agent", 0o775)?; + create_directory_with_user_group( + "/var/log/tedge/agent", + "tedge-agent", + "tedge-agent", + 0o775, + )?; info!("Initializing the tedge agent session"); mqtt_channel::init_session(&self.config.mqtt_config).await?; + Ok(()) } diff --git a/crates/core/tedge_agent/src/main.rs b/crates/core/tedge_agent/src/main.rs index 4847553f..4e71de4b 100644 --- a/crates/core/tedge_agent/src/main.rs +++ b/crates/core/tedge_agent/src/main.rs @@ -53,7 +53,7 @@ async fn main() -> Result<(), anyhow::Error> { SmAgentConfig::try_new(tedge_config_location)?, )?; if agent_opt.init { - agent.init_session().await?; + agent.init().await?; } else if agent_opt.clear { agent.clear_session().await?; } else { |