fixed restarts and long status messages

main
Joey Hines 2024-04-14 20:05:19 -06:00
parent 6a1682be63
commit de71b5124c
Signed by: joeyahines
GPG Key ID: 995E531F7A569DDB
3 changed files with 18 additions and 8 deletions

6
Cargo.lock generated
View File

@ -249,9 +249,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.34"
version = "0.4.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b"
checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e"
dependencies = [
"android-tzdata",
"iana-time-zone",
@ -406,7 +406,7 @@ dependencies = [
[[package]]
name = "daemon"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"bitflags 2.4.2",
"config",

View File

@ -1,6 +1,6 @@
[package]
name = "daemon"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -290,12 +290,21 @@ async fn service(
.await?;
}
ServiceAction::Restart => {
systemctl::stop(&service_name)?;
systemctl::restart(&service_name)?;
ctx.reply(format!("`{}` has been restarted", service_name))
.await?;
}
ServiceAction::Status => {
let status = systemctl::status(&service.name)?;
if status.len() > serenity::MESSAGE_CODE_LIMIT {
let file_name = format!("{}_status.log", service_name);
ctx.send(
CreateReply::default()
.attachment(CreateAttachment::bytes(status.into_bytes(), &file_name)),
)
.await?;
} else {
let mut msg = MessageBuilder::new();
msg.push_codeblock_safe(status, None);
@ -303,6 +312,7 @@ async fn service(
ctx.reply(msg.build()).await?;
}
}
}
} else {
ctx.reply(format!("Unknown service `{}`", service_name))
.await?;