diff --git a/crates/runtime-config/src/lib.rs b/crates/runtime-config/src/lib.rs index 8db0b536f..31526f4bf 100644 --- a/crates/runtime-config/src/lib.rs +++ b/crates/runtime-config/src/lib.rs @@ -99,6 +99,7 @@ where local_app_dir: Option, provided_state_dir: UserProvidedPath, provided_log_dir: UserProvidedPath, + refresh_logs: bool, ) -> anyhow::Result { let toml = match runtime_config_path { Some(runtime_config_path) => { @@ -120,13 +121,14 @@ where let toml_resolver = TomlResolver::new(&toml, local_app_dir, provided_state_dir, provided_log_dir); - Self::new(toml_resolver, runtime_config_path) + Self::new(toml_resolver, runtime_config_path, refresh_logs) } /// Creates a new resolved runtime configuration from a TOML table. pub fn new( toml_resolver: TomlResolver<'_>, runtime_config_path: Option<&Path>, + refresh_logs: bool, ) -> anyhow::Result { let runtime_config_dir = runtime_config_path .and_then(Path::parent) @@ -141,6 +143,11 @@ where let toml = toml_resolver.toml(); let log_dir = toml_resolver.log_dir()?; + + if refresh_logs { + let _ = Self::resolve_log_dir(&log_dir); + } + let max_instance_memory = toml_resolver.max_instance_memory()?; let source = TomlRuntimeConfigSource::new( @@ -166,6 +173,14 @@ where }) } + fn resolve_log_dir(log_dir: &Option) -> std::io::Result<()> { + if let Some(path) = log_dir { + std::fs::remove_dir_all(path) + } else { + Ok(()) + } + } + /// The fully resolved state directory. pub fn state_dir(&self) -> Option { self.state_dir.clone() @@ -493,6 +508,7 @@ mod tests { ResolvedRuntimeConfig::::new( toml_resolver(&toml), Some(path.as_ref()), + false, ) } }; diff --git a/crates/runtime-factors/src/build.rs b/crates/runtime-factors/src/build.rs index b1c837f8a..36730dd51 100644 --- a/crates/runtime-factors/src/build.rs +++ b/crates/runtime-factors/src/build.rs @@ -28,6 +28,7 @@ impl RuntimeFactorsBuilder for FactorsBuilder { config.local_app_dir.clone().map(PathBuf::from), config.state_dir.clone(), config.log_dir.clone(), + config.refresh_logs, )?; runtime_config.summarize(config.runtime_config_file.as_deref()); diff --git a/crates/trigger/src/cli.rs b/crates/trigger/src/cli.rs index db8e80a8f..72639c819 100644 --- a/crates/trigger/src/cli.rs +++ b/crates/trigger/src/cli.rs @@ -27,6 +27,7 @@ pub use stdio::StdioLoggingExecutorHooks; pub use summary::{KeyValueDefaultStoreSummaryHook, SqliteDefaultStoreSummaryHook}; pub const APP_LOG_DIR: &str = "APP_LOG_DIR"; +pub const SPIN_REFRESH_LOGS: &str = "SPIN_REFRESH_LOGS"; pub const DISABLE_WASMTIME_CACHE: &str = "DISABLE_WASMTIME_CACHE"; pub const FOLLOW_LOG_OPT: &str = "FOLLOW_ID"; pub const WASMTIME_CACHE_FILE: &str = "WASMTIME_CACHE_FILE"; @@ -54,6 +55,13 @@ pub struct FactorsTriggerCommand, B: RuntimeFactorsBuilde )] pub log: Option, + /// If set, Spin deletes the log files before starting the application. + #[clap( + name = SPIN_REFRESH_LOGS, + long = "refresh-logs", + )] + pub refresh_logs: bool, + /// Disable Wasmtime cache. #[clap( name = DISABLE_WASMTIME_CACHE, @@ -139,6 +147,8 @@ pub struct FactorsConfig { pub follow_components: FollowComponents, /// Log directory for component stdout/stderr. pub log_dir: UserProvidedPath, + /// Whether to refresh logs when restarted. + pub refresh_logs: bool, } /// An empty implementation of clap::Args to be used as TriggerExecutor::RunConfig @@ -220,6 +230,7 @@ impl, B: RuntimeFactorsBuilder> FactorsTriggerCommand