add separate archive directory

This commit is contained in:
tom committed 2026-10-07 23:16:17 +02:00
1 parent e824432824
commit a59487c468
9 files changed
+20 -17

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@ pub async fn subcommand(arg: &ArgMatches, pool: DbPool) -> Result<(), String>{
return Err("Server with this name already exists".to_string())
}
let path = config.config_path + "/" + server_name + "/";
let path = config.config_dir + "/" + server_name + "/";
create_dir(&path).await.map_err(|e| format!("failed to create the config folder, reason : {}", e))?;
+1 -1
View File
@@ -31,7 +31,7 @@ pub async fn subcommand(arguments: &ArgMatches, pool: DbPool) -> Result<(), Stri
Err(e) => { return Err(format!("An error occured : {:?}", e)); },
Ok(server) => server
};
let path = Config::load().config_path + "/" + &server.name;
let path = Config::load().config_dir + "/" + &server.name;
if server.status == ServerStatus::Running {
eprintln!("warning: the server is currently running, changes will no be applied until the next start");
+1 -1
View File
@@ -29,7 +29,7 @@ pub async fn subcommand(arguments: &ArgMatches, pool: &DbPool, docker: &Docker)
return Err("servver was not found".to_string());
}
let path = config.config_path + "/" + server_name;
let path = config.config_dir + "/" + server_name;
fs::remove_dir_all(path).map_err(|e| format!("failed to remove the server directory, reason : {}", e))?;
Ok(())
+2 -1
View File
@@ -22,7 +22,8 @@ pub async fn subcommand(arguments: &ArgMatches, pool: DbPool) -> Result<(), Stri
let wanted_state = match arguments.get_one::<String>("STATE").unwrap().as_str() {
"stopped" => {ServerStatus::Stopped},
"running" => {ServerStatus::Running},
_ => { return Err("invalid state, must be `stoppped` or `running`".to_string()) }
"archived" => {ServerStatus::Archived},
_ => { return Err("invalid state, must be `stoppped`, `running` or `archived`".to_string()) }
};
let conn = &mut pool.get().unwrap();
+4 -2
View File
@@ -1,7 +1,8 @@
use std::env;
pub struct Config {
pub config_path: String,
pub config_dir: String,
pub archive_dir: String,
pub lrzip_path: String,
pub tar_path: String,
pub shell_path: String,
@@ -11,7 +12,8 @@ pub struct Config {
impl Config {
pub fn load() -> Self {
Self {
config_path: env::var("DMM_CONFIG_PATH").unwrap_or_else(|_| "/raid/crit/mc_servers".to_string()),
config_dir: env::var("DMM_CONFIG_DIR").unwrap_or_else(|_| "/home/tom/mc_servers".to_string()),
archive_dir: env::var("DMM_ARCHIVE_DIR").unwrap_or_else(|_| "/raid/crit/mc_servers_archives".to_string()),
lrzip_path: env::var("DMM_LRZIP_PATH").unwrap_or_else(|_| "lrzip".to_string()),
tar_path: env::var("DMM_TAR_PATH").unwrap_or_else(|_| "tar".to_string()),
shell_path: env::var("DMM_SHELL_PATH").unwrap_or_else(|_| "sh".to_string()),
+2 -2
View File
@@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/29 21:22:17 by tomoron #+# #+# */
/* Updated: 2026/06/17 17:21:44 by tomoron ### ########.fr */
/* Updated: 2026/10/07 22:23:00 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@@ -40,7 +40,7 @@ mod migrations;
mod tests;
fn get_connection_pool() -> DbPool {
let database_url = "sqlite://".to_string() + &Config::load().config_path + "/db.sqlite";
let database_url = "sqlite://".to_string() + &Config::load().config_dir + "/db.sqlite";
let manager = ConnectionManager::<SqliteConnection>::new(&database_url);
Pool::builder()
+2 -2
View File
@@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/07 17:23:09 by tomoron #+# #+# */
/* Updated: 2026/07/22 17:50:17 by tomoron ### ########.fr */
/* Updated: 2026/10/07 23:12:58 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,7 +29,7 @@ use regex::Regex;
use chrono::Utc;
enum ClientState {
pub enum ClientState {
PreHandshake,
Status,
Login,
+4 -4
View File
@@ -12,13 +12,13 @@ pub async fn archive_server(server: &Servers, pool: &DbPool) -> Result<(), Strin
println!("Starting compression (this might take a while)");
let cmd = format!("cd {} && {} cf /dev/stdout {} | {} - -Q -o {}.tar.lrz", config.config_path, config.tar_path, server.name, config.lrzip_path, server.name);
let cmd = format!("cd {} && {} cf /dev/stdout {} | {} - -Q -o {}/{}.tar.lrz", config.config_dir, config.tar_path, server.name, config.lrzip_path, config.archive_dir, server.name);
println!("archiving with command : {}", cmd);
let _ = async_process::Command::new(config.shell_path).arg("-c").arg(cmd).output().await.map_err(|e| format!("compression failed : {}", e))?;
std::fs::remove_dir_all(config.config_path.to_owned() + "/" + &server.name).map_err(|e| format!("Failed to delete server directory: {}", e))?;
std::fs::remove_dir_all(config.config_dir.to_owned() + "/" + &server.name).map_err(|e| format!("Failed to delete server directory: {}", e))?;
diesel::update(servers).filter(name.eq(&server.name)).set(status.eq(ServerStatus::Archived)).execute(conn).map_err(|e| format!("Failed to set the server as achived :{}", e))?;
Ok(())
@@ -29,12 +29,12 @@ pub async fn unarchive_server(server: &Servers) -> Result<(), String> {
println!("Starting decompression (this might take a while)");
let cmd = format!("cd {} && cat {}.tar.lrz | {} -d - | {} x", config.config_path, server.name, config.lrzip_path, config.tar_path);
let cmd = format!("cd {} && cat {}.tar.lrz | {} -d - | {} xC {}", config.archive_dir, server.name, config.lrzip_path, config.tar_path, config.config_dir);
println!("unarchiving with command : {}", cmd);
let _ = async_process::Command::new(config.shell_path).arg("-c").arg(cmd).output().await.map_err(|e| format!("decompression failed : {}", e))?;
std::fs::remove_file(config.config_path + "/" + &server.name + ".tar.lrz").map_err(|e| format!("Failed to delete the archive of the server : {}", e))?;
std::fs::remove_file(config.archive_dir + "/" + &server.name + ".tar.lrz").map_err(|e| format!("Failed to delete the archive of the server : {}", e))?;
Ok(())
}
+3 -3
View File
@@ -13,9 +13,9 @@ async fn start_docker_container(docker: &Docker, name: &String) -> Result<String
return Err("Container already exists".to_string())
}
let config_path = crate::Config::load().config_path;
let config_dir = crate::Config::load().config_dir;
let env_file = std::fs::read_to_string(config_path.clone() + "/" + name + "/env").map_err(|e| format!("Failed to read env file {}", e))?;
let env_file = std::fs::read_to_string(config_dir.clone() + "/" + name + "/env").map_err(|e| format!("Failed to read env file {}", e))?;
let env = env_file.split("\n").filter_map(|x| if x.len() == 0 { None } else { Some(x.to_string()) } ).collect();
@@ -29,7 +29,7 @@ async fn start_docker_container(docker: &Docker, name: &String) -> Result<String
let mut mount = Mount::default();
mount.typ = Some(MountType::BIND);
mount.target = Some("/data".to_string());
mount.source = Some(config_path + "/" + name + "/server");
mount.source = Some(config_dir + "/" + name + "/server");
mount.read_only = Some(false);
let mut host_config = HostConfig::default();