Compare commits
No commits in common. "2687ae5457854452cafcd06c9833f71fac93c3f7" and "1f8a81e731ab3533d6c33ca75ae8b7e3558a07e4" have entirely different histories.
2687ae5457
...
1f8a81e731
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -207,12 +207,6 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg_aliases"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.38"
|
version = "0.4.38"
|
||||||
@ -288,16 +282,6 @@ version = "0.8.7"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ctrlc"
|
|
||||||
version = "3.4.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "90eeab0aa92f3f9b4e87f258c72b139c207d251f9cbc1080a0086b86a8870dd3"
|
|
||||||
dependencies = [
|
|
||||||
"nix",
|
|
||||||
"windows-sys 0.59.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deranged"
|
name = "deranged"
|
||||||
version = "0.3.11"
|
version = "0.3.11"
|
||||||
@ -316,7 +300,6 @@ dependencies = [
|
|||||||
"bollard",
|
"bollard",
|
||||||
"clap",
|
"clap",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
"ctrlc",
|
|
||||||
"flexi_logger",
|
"flexi_logger",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
@ -749,18 +732,6 @@ dependencies = [
|
|||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nix"
|
|
||||||
version = "0.29.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"cfg-if",
|
|
||||||
"cfg_aliases",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nu-ansi-term"
|
name = "nu-ansi-term"
|
||||||
version = "0.50.1"
|
version = "0.50.1"
|
||||||
|
@ -11,7 +11,6 @@ anyhow = "1.0.88"
|
|||||||
bollard = { version = "0.17.1", features = ["ssl", "json_data_content", "tokio-stream"] }
|
bollard = { version = "0.17.1", features = ["ssl", "json_data_content", "tokio-stream"] }
|
||||||
clap = { version = "4.5.17", features = ["derive"] }
|
clap = { version = "4.5.17", features = ["derive"] }
|
||||||
clap_derive = "4.5.13"
|
clap_derive = "4.5.13"
|
||||||
ctrlc = "3.4.5"
|
|
||||||
flexi_logger = "0.29.0"
|
flexi_logger = "0.29.0"
|
||||||
futures-util = "0.3.30"
|
futures-util = "0.3.30"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
@ -20,9 +19,3 @@ parse_duration = "2.1.1"
|
|||||||
serde = "1.0.210"
|
serde = "1.0.210"
|
||||||
tokio = {version = "1.40.0", features = ["full"]}
|
tokio = {version = "1.40.0", features = ["full"]}
|
||||||
tokio-macros = "2.4.0"
|
tokio-macros = "2.4.0"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
opt-level = 3
|
|
||||||
debug = false
|
|
||||||
lto = true
|
|
||||||
strip = true
|
|
||||||
|
12
Dockerfile
12
Dockerfile
@ -5,15 +5,13 @@ FROM chef AS planner
|
|||||||
COPY . .
|
COPY . .
|
||||||
RUN cargo chef prepare --recipe-path recipe.json
|
RUN cargo chef prepare --recipe-path recipe.json
|
||||||
|
|
||||||
FROM chef AS builder
|
FROM chef AS builder
|
||||||
COPY --from=planner /app/recipe.json recipe.json
|
COPY --from=planner /app/recipe.json recipe.json
|
||||||
RUN cargo chef cook --release --recipe-path recipe.json
|
RUN cargo chef cook --recipe-path recipe.json
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN cargo build --release
|
RUN cargo build
|
||||||
|
|
||||||
FROM debian:12-slim AS runtime
|
FROM debian:12-slim AS runtime
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/target/release/doctor-restart /usr/local/bin
|
COPY --from=builder /app/target/debug/doctor-restart /usr/local/bin
|
||||||
STOPSIGNAL SIGINT
|
ENTRYPOINT ["/usr/local/bin/doctor-restart"]
|
||||||
ENTRYPOINT ["/usr/local/bin/doctor-restart"]
|
|
||||||
CMD ["-l", "auto-restart.unhealthy", "-i", "10s", "-u", "35s"]
|
|
26
src/main.rs
26
src/main.rs
@ -160,25 +160,13 @@ async fn restart_task(connection: Arc<Docker>, mut rx: mpsc::Receiver<Containers
|
|||||||
log::warn!("restart -> container: {}...", &container_id);
|
log::warn!("restart -> container: {}...", &container_id);
|
||||||
let res = restart_container(&connection, container_id.as_str()).await;
|
let res = restart_container(&connection, container_id.as_str()).await;
|
||||||
match res {
|
match res {
|
||||||
Ok(_) => log::info!("ok"),
|
Ok(_) => log::info!("ok\n"),
|
||||||
Err(e) => log::error!("error: \n{e:?}"),
|
Err(e) => log::error!("error: \n{e:?}\n"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shutdown_control(shutdown: Option<mpsc::Sender<()>>) {
|
|
||||||
let mut shutdown = shutdown;
|
|
||||||
let res = ctrlc::set_handler(move || {
|
|
||||||
log::info!("recieved Ctrl-C");
|
|
||||||
shutdown.take();
|
|
||||||
});
|
|
||||||
|
|
||||||
if res.is_ok() {
|
|
||||||
log::info!("Press Ctrl-C to stop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
let logger = create_logger()?;
|
let logger = create_logger()?;
|
||||||
@ -202,8 +190,6 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
let interval = cli.interval;
|
let interval = cli.interval;
|
||||||
let unhealthy_timeout = cli.unhealthy_timeout;
|
let unhealthy_timeout = cli.unhealthy_timeout;
|
||||||
|
|
||||||
shutdown_control(Some(shutdown_tx));
|
|
||||||
|
|
||||||
tokio::try_join!(
|
tokio::try_join!(
|
||||||
tokio::spawn(query_task(
|
tokio::spawn(query_task(
|
||||||
query_connection,
|
query_connection,
|
||||||
@ -213,7 +199,13 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
cli
|
cli
|
||||||
)),
|
)),
|
||||||
tokio::spawn(filter_task(unhealthy_timeout, filter_rx, filter_tx)),
|
tokio::spawn(filter_task(unhealthy_timeout, filter_rx, filter_tx)),
|
||||||
tokio::spawn(restart_task(restart_connection, restart_rx))
|
tokio::spawn(restart_task(restart_connection, restart_rx)),
|
||||||
|
tokio::spawn(async {
|
||||||
|
log::debug!("shutdown -> sleep");
|
||||||
|
tokio::time::sleep(Duration::from_secs(80)).await;
|
||||||
|
log::warn!("shutdown -> drop");
|
||||||
|
drop(shutdown_tx);
|
||||||
|
})
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
drop(logger);
|
drop(logger);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user