diff --git a/growpi.service b/growpi.service index afe8604..6a99318 100644 --- a/growpi.service +++ b/growpi.service @@ -7,6 +7,7 @@ Type=simple Restart=always RestartSec=10 ExecStart=/opt/growpi/growpi +WorkingDirectory=/opt/growpi [Install] WantedBy=mutli-user.target diff --git a/src/main.rs b/src/main.rs index 288ad24..3e636df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,11 +19,16 @@ mod state; fn load_config() -> config::Configuration { let config = Configuration::from_file(std::path::Path::new("./growpi.toml")); - if let Err(config) = &config { - println!("Could not load config: {}", config); + match config { + Ok(config) => config, + Err(_) => { + let config = Configuration::default(); + config + .save_to_file(std::path::Path::new("./growpi.toml")) + .expect("Could not create default config in ./growpi.toml"); + config + } } - - config.unwrap_or_default() } #[tokio::main(flavor = "current_thread")]