initial commit
This commit is contained in:
commit
0690f6b4e6
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
1368
Cargo.lock
generated
Normal file
1368
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "doctor-restart"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.88"
|
||||
bollard = { version = "0.17.1", features = ["ssl", "json_data_content", "tokio-stream"] }
|
||||
futures-util = "0.3.30"
|
||||
tokio = {version = "1.40.0", features = ["full"]}
|
||||
tokio-macros = "2.4.0"
|
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@ -0,0 +1,17 @@
|
||||
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
|
||||
WORKDIR /app
|
||||
|
||||
FROM chef AS planner
|
||||
COPY . .
|
||||
RUN cargo chef prepare --recipe-path recipe.json
|
||||
|
||||
FROM chef AS builder
|
||||
COPY --from=planner /app/recipe.json recipe.json
|
||||
RUN cargo chef cook --recipe-path recipe.json
|
||||
COPY . .
|
||||
RUN cargo build
|
||||
|
||||
FROM debian:12-slim AS runtime
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/target/debug/doctor-restart /usr/local/bin
|
||||
ENTRYPOINT ["/usr/local/bin/doctor-restart"]
|
11
docker-compose.yml
Normal file
11
docker-compose.yml
Normal file
@ -0,0 +1,11 @@
|
||||
services:
|
||||
watchdog:
|
||||
build: .
|
||||
restart: no
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-file: '5'
|
||||
max-size: 10m
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
41
src/main.rs
Normal file
41
src/main.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use bollard::{API_DEFAULT_VERSION, Docker};
|
||||
use futures_util::future::TryFutureExt;
|
||||
use bollard::container::ListContainersOptions;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::default::Default;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let connection = Docker::connect_with_defaults().expect("connection");
|
||||
|
||||
let mut filters = HashMap::new();
|
||||
filters.insert("status", vec!["running"]);
|
||||
filters.insert("label", vec!["auto-restart.unhealthy"]);
|
||||
filters.insert("health", vec!["unhealthy"]);
|
||||
|
||||
let options = Some(ListContainersOptions{
|
||||
all: true,
|
||||
filters,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let result = connection.list_containers(options).await;
|
||||
|
||||
//let result = connection.ping().map_ok(|_| Ok::<_, ()>(println!("Connected!"))).await;
|
||||
|
||||
if let Err(x) = result {
|
||||
eprintln!("error: {:#?}", x);
|
||||
} else if let Ok(found) = result {
|
||||
println!("found: {}", found.len());
|
||||
for container in found {
|
||||
let container_id = container.id.unwrap();
|
||||
println!("{:?}", container.names.unwrap_or(vec![container_id.clone()]));
|
||||
|
||||
//let r = connection.restart_container(container_id.as_str(), None).await;
|
||||
//println!("{:?}", r);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue
Block a user