summaryrefslogtreecommitdiffstats
path: root/plugins/c8y_log_plugin/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/c8y_log_plugin/src/main.rs')
-rw-r--r--plugins/c8y_log_plugin/src/main.rs55
1 files changed, 16 insertions, 39 deletions
diff --git a/plugins/c8y_log_plugin/src/main.rs b/plugins/c8y_log_plugin/src/main.rs
index 42e28053..acee7dbf 100644
--- a/plugins/c8y_log_plugin/src/main.rs
+++ b/plugins/c8y_log_plugin/src/main.rs
@@ -11,11 +11,7 @@ use clap::Parser;
use inotify::{EventMask, EventStream};
use inotify::{Inotify, WatchMask};
use mqtt_channel::{Connection, StreamExt};
-use std::{
- fs::OpenOptions,
- io::Write,
- path::{Path, PathBuf},
-};
+use std::path::{Path, PathBuf};
use tedge_config::{
ConfigRepository, ConfigSettingAccessor, LogPathSetting, MqttPortSetting, TEdgeConfig,
DEFAULT_TEDGE_CONFIG_PATH,
@@ -191,27 +187,6 @@ fn init(config_dir: &Path, logs_dir: &Path) -> Result<(), anyhow::Error> {
Ok(())
}
-/// append the log plugin file with software-management logs
-/// assumes file is already created.
-fn create_default_log_plugin_file(path_to_toml: &str, logs_dir: &str) -> Result<(), anyhow::Error> {
- let logs_path = format!("{logs_dir}/tedge/agent/software-*");
- let data = toml::toml! {
- files = [
- { type = "software-management", path = logs_path }
- ]
- };
-
- let mut toml_file = OpenOptions::new()
- .append(true)
- .create(false)
- .open(path_to_toml)
- .map_err(|error| {
- anyhow::anyhow!("Unable to open file: {}. Error: {}", path_to_toml, error)
- })?;
- toml_file.write_all(data.to_string().as_bytes())?;
- Ok(())
-}
-
/// for the log plugin to work the following directories and files are needed:
///
/// Directories:
@@ -221,7 +196,7 @@ fn create_default_log_plugin_file(path_to_toml: &str, logs_dir: &str) -> Result<
///
/// Files:
/// - CONFIG_DIR/operations/c8y/c8y_LogfileRequest
-/// - CONFIG_DIR/c8y/log/c8y-log-plugin.toml
+/// - CONFIG_DIR/c8y/c8y-log-plugin.toml
fn create_init_logs_directories_and_files(
config_dir: &str,
logs_dir: &str,
@@ -242,24 +217,26 @@ fn create_init_logs_directories_and_files(
&format!("{config_dir}/operations/c8y/c8y_LogfileRequest"),
"tedge",
"tedge",
- 0o755,
+ 0o644,
+ None,
)?;
// creating c8y directory
- create_directory_with_user_group(&format!("{config_dir}/c8y"), "tedge", "tedge", 0o755)?;
- // creating c8y-log-plugin.toml
+ create_directory_with_user_group(&format!("{config_dir}/c8y"), "root", "root", 0o1777)?;
- // NOTE: file needs 775 permission or inotify can not watch for changes inside the file
+ // creating c8y-log-plugin.toml
+ let logs_path = format!("{logs_dir}/tedge/agent/software-*");
+ let data = toml::toml! {
+ files = [
+ { type = "software-management", path = logs_path }
+ ]
+ };
create_file_with_user_group(
&format!("{config_dir}/{DEFAULT_PLUGIN_CONFIG_FILE}"),
- "tedge",
- "tedge",
- 0o775,
+ "root",
+ "root",
+ 0o644,
+ Some(&data.to_string()),
)?;
- // append default content to c8y-log-plugin.toml
- create_default_log_plugin_file(
- &format!("{config_dir}/{DEFAULT_PLUGIN_CONFIG_FILE}"),
- logs_dir,
- )?;
Ok(())
}