Compare commits
3 Commits
1f8a81e731
...
2687ae5457
Author | SHA1 | Date | |
---|---|---|---|
2687ae5457 | |||
2a51098daf | |||
03e4e670a9 |
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -207,6 +207,12 @@ 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"
|
||||||
@ -282,6 +288,16 @@ 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"
|
||||||
@ -300,6 +316,7 @@ dependencies = [
|
|||||||
"bollard",
|
"bollard",
|
||||||
"clap",
|
"clap",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
|
"ctrlc",
|
||||||
"flexi_logger",
|
"flexi_logger",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
@ -732,6 +749,18 @@ 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,6 +11,7 @@ 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"
|
||||||
@ -19,3 +20,9 @@ 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,13 +5,15 @@ 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 --recipe-path recipe.json
|
RUN cargo chef cook --release --recipe-path recipe.json
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN cargo build
|
RUN cargo build --release
|
||||||
|
|
||||||
FROM debian:12-slim AS runtime
|
FROM debian:12-slim AS runtime
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/target/debug/doctor-restart /usr/local/bin
|
COPY --from=builder /app/target/release/doctor-restart /usr/local/bin
|
||||||
ENTRYPOINT ["/usr/local/bin/doctor-restart"]
|
STOPSIGNAL SIGINT
|
||||||
|
ENTRYPOINT ["/usr/local/bin/doctor-restart"]
|
||||||
|
CMD ["-l", "auto-restart.unhealthy", "-i", "10s", "-u", "35s"]
|
||||||
|
26
src/main.rs
26
src/main.rs
@ -160,13 +160,25 @@ 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\n"),
|
Ok(_) => log::info!("ok"),
|
||||||
Err(e) => log::error!("error: \n{e:?}\n"),
|
Err(e) => log::error!("error: \n{e:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()?;
|
||||||
@ -190,6 +202,8 @@ 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,
|
||||||
@ -199,13 +213,7 @@ 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…
Reference in New Issue
Block a user