Fix directories and add service files

This commit is contained in:
Adrian Woźniak 2024-06-14 12:28:32 +02:00
parent b66b2cee57
commit 272d950bae
7 changed files with 74 additions and 44 deletions

14
7dtd-daemon.service Normal file
View File

@ -0,0 +1,14 @@
[Unit]
Description=Synchronize 7dtd mods
After=sysinit.target local-fs.target
[Service]
Restart=on-failure
RestartSec=4
ExecStart=/usr/bin/sync-7dtd-daemon
Environment=RUST_LOG=ERROR
[Install]
WantedBy=multi-user.target

60
Cargo.lock generated
View File

@ -142,21 +142,6 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216"
[[package]]
name = "daemon"
version = "0.1.0"
dependencies = [
"directories",
"mod_list",
"postcard",
"serde",
"tokio",
"tracing",
"tracing-subscriber",
"urlencoded",
"urlencoding",
]
[[package]]
name = "derive_more"
version = "0.99.17"
@ -494,21 +479,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58"
[[package]]
name = "mods-server"
version = "0.1.0"
dependencies = [
"futures-util",
"heapless 0.8.0",
"mod_list",
"postcard",
"serde",
"tokio",
"tracing",
"tracing-subscriber",
"urlencoding",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
@ -976,6 +946,36 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "sync-7dtd-daemon"
version = "0.1.0"
dependencies = [
"directories",
"mod_list",
"postcard",
"serde",
"tokio",
"tracing",
"tracing-subscriber",
"urlencoded",
"urlencoding",
]
[[package]]
name = "sync-7dtd-server"
version = "0.1.0"
dependencies = [
"futures-util",
"heapless 0.8.0",
"mod_list",
"postcard",
"serde",
"tokio",
"tracing",
"tracing-subscriber",
"urlencoding",
]
[[package]]
name = "thiserror"
version = "1.0.61"

View File

@ -1,5 +1,5 @@
[package]
name = "daemon"
name = "sync-7dtd-daemon"
version = "0.1.0"
edition = "2021"

View File

@ -128,6 +128,7 @@ async fn main() {
.expect("Failed to create mod file parent dir");
};
tracing::info!("Writing file: {file_path:?}");
if let Err(e) = tokio::fs::write(file_path, &buffer).await {
tracing::warn!("Unable to save {f:?}: {e}");
break;

View File

@ -102,14 +102,14 @@ pub async fn refresh_mod_list(dir: PathBuf, mod_list: ModList) -> std::io::Resul
let Some(name) = f.file_name().to_str().map(String::from) else {
continue;
};
let date = meta.modified()?;
let mut files = Vec::with_capacity(1024);
let file = ModFileInfo {
path: file_relative(&dir_string, f.path()),
ts: date,
};
files.push(file);
// let date = meta.modified()?;
// let file = ModFileInfo {
// path: file_relative(&dir_string, f.path()),
// ts: date,
// };
// files.push(file);
read_rec(&dir_string, f.path(), &mut files)?;
let newest = files
@ -141,12 +141,12 @@ fn read_rec(dir: &str, path: PathBuf, res: &mut Vec<ModFileInfo>) -> std::io::Re
let f = f?;
let meta = f.metadata()?;
if meta.is_dir() {
let date = meta.modified()?;
let file = ModFileInfo {
path: file_relative(dir, f.path()),
ts: date,
};
res.push(file);
// let date = meta.modified()?;
// let file = ModFileInfo {
// path: file_relative(dir, f.path()),
// ts: date,
// };
// res.push(file);
read_rec(&dir, f.path(), res)?;
} else if meta.is_file() {
let date = meta.modified()?;

15
server.service Normal file
View File

@ -0,0 +1,15 @@
[Unit]
Description=7dtd sync server
After=sysinit.target local-fs.target
[Service]
Restart=on-failure
RestartSec=4
ExecStart=/usr/bin/sync-7dtd-server
Environment=RUST_LOG=ERROR
Environment=7DTD_MODS_DIR=/home/7dtd/server/Mods
[Install]
WantedBy=multi-user.target

View File

@ -1,5 +1,5 @@
[package]
name = "mods-server"
name = "sync-7dtd-server"
version = "0.1.0"
edition = "2021"