From 6cd092c30fd7c22428c0c0792987ef419a781ff5 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Sun, 14 May 2023 21:16:09 +0200 Subject: [PATCH] try to create log path, if not exists. expose state file in config (important for multi channels) --- assets/ffplayout.yml | 1 + docker/Almalinux.Dockerfile | 2 +- docker/README.md | 15 +++++++++++---- ffplayout-engine/src/main.rs | 11 ++++++++++- lib/src/utils/config.rs | 19 +++++++++++-------- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/assets/ffplayout.yml b/assets/ffplayout.yml index 153eb62f..f2285e24 100644 --- a/assets/ffplayout.yml +++ b/assets/ffplayout.yml @@ -6,6 +6,7 @@ general: on linux. 'stop_threshold' stop ffplayout, if it is async in time above this value. A number below 3 can cause unexpected errors. stop_threshold: 11 + stat_file: .ffp_status rpc_server: help_text: Run a JSON RPC server, for getting infos about current playing and diff --git a/docker/Almalinux.Dockerfile b/docker/Almalinux.Dockerfile index 265ee783..6f97af2a 100644 --- a/docker/Almalinux.Dockerfile +++ b/docker/Almalinux.Dockerfile @@ -16,7 +16,7 @@ RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \ FROM base -ARG FFPLAYOUT_VERSION=0.17.0 +ARG FFPLAYOUT_VERSION=0.17.1 COPY README.md *.rpm /tmp/ RUN dnf update -y && \ diff --git a/docker/README.md b/docker/README.md index 0b40cf17..cf4df3d4 100644 --- a/docker/README.md +++ b/docker/README.md @@ -30,10 +30,17 @@ It may be useful to create/link volume for those folders/files. ## Docker -How to build the image -`docker build -t ffplayout-image .` -`docker build -f fromSource.Dockerfile -t ffplayout-image:from-source .` -`docker build -f Almalinux.Dockerfile -t ffplayout-image:almalinux .` +How to build the image:\ +```BASH +# build default +docker build -t ffplayout-image . + +# build ffmpeg from source +docker build -f fromSource.Dockerfile -t ffplayout-image:from-source . + +# build with current almalinux image +docker build -f Almalinux.Dockerfile -t ffplayout-image:almalinux . +``` example of command to start the container: diff --git a/ffplayout-engine/src/main.rs b/ffplayout-engine/src/main.rs index 48922a66..012e6587 100644 --- a/ffplayout-engine/src/main.rs +++ b/ffplayout-engine/src/main.rs @@ -1,6 +1,6 @@ use std::{ fs::{self, File}, - path::PathBuf, + path::{Path, PathBuf}, process::exit, sync::{Arc, Mutex}, thread, @@ -98,6 +98,15 @@ fn main() { let proc_ctl2 = proc_control.clone(); let messages = Arc::new(Mutex::new(Vec::new())); + // try to create logging folder, if not exist + if config.logging.log_to_file && !Path::new(&config.logging.log_path).is_dir() { + if let Err(e) = fs::create_dir_all(&config.logging.log_path) { + println!("Logging path not exists! {e}"); + + exit(1); + } + } + let logging = init_logging(&config, Some(proc_ctl1), Some(messages.clone())); CombinedLogger::init(logging).unwrap(); diff --git a/lib/src/utils/config.rs b/lib/src/utils/config.rs index d2795be0..d407e6c2 100644 --- a/lib/src/utils/config.rs +++ b/lib/src/utils/config.rs @@ -146,11 +146,11 @@ pub struct General { pub help_text: String, pub stop_threshold: f64, - #[serde(skip_serializing, skip_deserializing)] - pub generate: Option>, + #[serde(default)] + pub stat_file: String, #[serde(skip_serializing, skip_deserializing)] - pub stat_file: String, + pub generate: Option>, #[serde(skip_serializing, skip_deserializing)] pub ffmpeg_filters: Vec, @@ -336,11 +336,14 @@ impl PlayoutConfig { let mut config: PlayoutConfig = serde_yaml::from_reader(f).expect("Could not read config file."); config.general.generate = None; - config.general.stat_file = home_dir() - .unwrap_or_else(env::temp_dir) - .join(".ffp_status") - .display() - .to_string(); + + if config.general.stat_file.is_empty() { + config.general.stat_file = home_dir() + .unwrap_or_else(env::temp_dir) + .join(".ffp_status") + .display() + .to_string(); + } if config.logging.ingest_level.is_none() { config.logging.ingest_level = Some(config.logging.ffmpeg_level.clone())