Skip to content

Commit

Permalink
Merge pull request #83 from tmknight/dev/0.10.1
Browse files Browse the repository at this point in the history
v0.10.1
  • Loading branch information
tmknight authored Feb 21, 2024
2 parents 34a00da + 616c553 commit 226e361
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 87 deletions.
27 changes: 22 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

## 0.10.1

### Changed

- Binary options
- -v, --version replaced by -V, --version to be in alignment with standard practices
- Alphabetized help output for easier reading (lowercase then uppercase)

### Fixed

- Binary options
- -a, --post-action replaced by -P, --post-action to resolve conflict with -a, --apprise-url

## 0.10.0

There are several breaking changes; please read carefully
There are several breaking changes; please read carefully and refer to [README](https://github.com/tmknight/docker-autoheal/blob/main/README.md) for more details

### Added

- Binary options
- -m, --monitor-all switch to control monitoring of all containers
- Environment variables
- AUTOHEAL_MONITOR_ALL (TRUE/FALSE)
- AUTOHEAL_MONITOR_ALL (TRUE/FALSE) to control monitoring of all containers
- Container labels
- autoheal.monitor.enable (TRUE/FALSE) as override when AUTOHEAL_MONITOR_ALL set to TRUE
- autoheal.monitor.enable (TRUE/FALSE) to control monitoring of individual containers
- Overrides AUTOHEAL_MONITOR_ALL
- Returning last health 'ExitCode` and 'Output' to log (and webhook/apprise if configured) for unhealthy containers

### Changed

Expand All @@ -31,9 +48,9 @@ There are several breaking changes; please read carefully
### Removed

- Binary options
- -l, --container-label
- -l, --container-label (see --monitor-all and autoheal.monitor.enable)
- Environment variables
- AUTOHEAL_CONTAINER_LABEL
- AUTOHEAL_CONTAINER_LABEL (see --monitor-all and autoheal.monitor.enable)

## 0.9.0

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "docker-autoheal"
version = "0.10.0"
version = "0.10.1"
authors = ["Travis M Knight"]
license = "GPL-3.0"
description = "A cross-platform tool to monitor and remediate unhealthy Docker containers"
Expand Down
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Docker-Autoheal

[![GitHubRelease][GitHubReleaseBadge]][GitHubReleaseLink]
[![GitHubAssetDl][GitHubAssetDlBadge]][GitHubAssetDlLink]
[![DockerPublishing][DockerPublishingBadge]][DockerLink]
[![DockerSize][DockerSizeBadge]][DockerLink]
[![DockerPulls][DockerPullsBadge]][DockerLink]
Expand Down Expand Up @@ -50,45 +51,45 @@ Used when executed in native OS (NOTE: The environment variables are also accept

```bash
Options:
-a, --apprise-url <APPRISE_URL>
The apprise url
-c, --connection-type <CONNECTION_TYPE>
One of local, socket, http, or ssl
-s, --stop-timeout <STOP_TIMEOUT>
Time in seconds to wait for action to complete
-i, --interval <INTERVAL>
Time in seconds to check health
-d, --start-delay <START_DELAY>
Time in seconds to wait for first check
-h, --help Print help
-i, --interval <INTERVAL>
Time in seconds to check health
-j, --webhook-key <WEBHOOK_KEY>
The webhook json key string
-k, --key-path <KEY_PATH>
The fully qualified path to requisite ssl PEM files
-l, --log-all Enable logging of unhealthy containers where restart
is disabled (WARNING, this could be chatty)
-m, --monitor-all Enable monitoring off all containers that have a
healthcheck
-n, --tcp-host <TCP_HOST>
The hostname or IP address of the Docker host (when -c
http or ssl)
-p, --tcp-port <TCP_PORT>
The tcp port number of the Docker host (when -c http
or ssl)
-s, --stop-timeout <STOP_TIMEOUT>
Time in seconds to wait for action to complete
-t, --tcp-timeout <TCP_TIMEOUT>
Time in seconds to wait for connection to complete
-k, --key-path <KEY_PATH>
The fully qualified path to requisite ssl PEM files
-a, --apprise-url <APPRISE_URL>
The apprise url
-j, --webhook-key <WEBHOOK_KEY>
The webhook json key string
-w, --webhook-url <WEBHOOK_URL>
The webhook url
-a, --post-action <SCRIPT_PATH>
-P, --post-action <SCRIPT_PATH>
The absolute path to a script that should be executed
after container restart
-m, --monitor-all Enable monitoring off all containers that have a
healthcheck
-l, --log-all Enable logging of unhealthy containers where restart
is disabled (WARNING, this could be chatty)
-h, --help Print help
-v, --version Print version information
-V, --version Print version information
```

### Local

```bash
/usr/local/bin/docker-autoheal --container-label all > /var/log/docker-autoheal.log &
/usr/local/bin/docker-autoheal --monitor-all > /var/log/docker-autoheal.log &
```

Will connect to the local Docker host and monitor all containers
Expand All @@ -102,12 +103,12 @@ docker run -d --read-only \
--network=none \
--restart=always \
--env="AUTOHEAL_CONNECTION_TYPE=socket" \
--env="AUTOHEAL_CONTAINER_LABEL=autoheal" \
--env="AUTOHEAL_MONITOR_ALL=true" \
--volume=/var/run/docker.sock:/var/run/docker.sock:ro \
tmknight88/docker-autoheal:latest
```

Will connect to the Docker host via unix socket location /var/run/docker.sock or Windows named pipe location //./pipe/docker_engine and monitor only containers with a label named `autoheal` as the user with the specified `uid:gid`
Will connect to the Docker host via unix socket location /var/run/docker.sock or Windows named pipe location //./pipe/docker_engine and monitor all containers as the user with the specified `uid:gid`

### HTTP

Expand All @@ -117,13 +118,12 @@ docker run -d --read-only \
--name docker-autoheal \
--restart=always \
--env="AUTOHEAL_CONNECTION_TYPE=http" \
--env="AUTOHEAL_CONTAINER_LABEL=watch-me" \
--env="AUTOHEAL_TCP_HOST=MYHOST" \
--env="AUTOHEAL_TCP_PORT=2375" \
tmknight88/docker-autoheal:latest
```

Will connect to the Docker host via hostname or IP and the specified port and monitor only containers with a label named `watch-me` as the user with the specified `uid:gid`
Will connect to the Docker host via hostname or IP and the specified port and monitor only containers with a label `autoheal.monitor.enable=true` as the user with the specified `uid:gid`

### Logging

Expand All @@ -142,13 +142,11 @@ Example log output when docker-autoheal is in action

### Docker Labels

a) Apply the label `autoheal=true` to your container to have it watched (only the label name is assessed, the value is not currently used)

b) Set ENV `AUTOHEAL_CONTAINER_LABEL` to that label name (e.g. `AUTOHEAL_CONTAINER_LABEL=autoheal`)
a) Apply the label `autoheal.monitor.enable=true` to your container to have it watched

OR

c) Set ENV `AUTOHEAL_CONTAINER_LABEL=all` to watch all running containers
b) Set ENV `AUTOHEAL_MONITOR_ALL=true` (or apply `--monitor-all` to the binary) to watch all running containers

### SSL Connection Type

Expand Down Expand Up @@ -187,9 +185,11 @@ docker run ... -v /etc/localtime:/etc/localtime:ro

- [willfarrell](https://github.com/willfarrell)

[GitHubReleaseBadge]: https://github.com/tmknight/docker-autoheal/actions/workflows/github-release.yml/badge.svg
[GitHubReleaseBadge]: https://img.shields.io/github/actions/workflow/status/tmknight/docker-autoheal/github-release.yml?branch=main&style=flat&logo=github&color=347d39&label=generate%20release&cacheSeconds=21600
[GitHubReleaseLink]: https://github.com/tmknight/docker-autoheal/releases
[DockerPublishingBadge]: https://github.com/tmknight/docker-autoheal/actions/workflows/docker-publish.yml/badge.svg
[DockerPullsBadge]: https://badgen.net/docker/pulls/tmknight88/docker-autoheal?icon=docker&label=Docker+Pulls&labelColor=black&color=green
[DockerSizeBadge]: https://badgen.net/docker/size/tmknight88/docker-autoheal?icon=docker&label=Docker+Size&labelColor=black&color=green
[DockerPublishingBadge]: https://img.shields.io/github/actions/workflow/status/tmknight/docker-autoheal/docker-publish.yml?branch=main&style=flat&logo=github&color=347d39&label=publish%20image&cacheSeconds=21600
[DockerPullsBadge]: https://img.shields.io/docker/pulls/tmknight88/docker-autoheal?style=flat&logo=docker&color=blue&cacheSeconds=21600
[DockerSizeBadge]: https://img.shields.io/docker/image-size/tmknight88/docker-autoheal?sort=date&arch=amd64&style=flat&logo=docker&color=blue&cacheSeconds=21600
[DockerLink]: https://hub.docker.com/r/tmknight88/docker-autoheal
[GithubAssetDlBadge]: https://img.shields.io/github/downloads/tmknight/docker-autoheal/total?style=flat&logo=github&color=347d39&label=release%20downloads&cacheSeconds=21600
[GithubAssetDlLink]: https://github.com/tmknight/docker-autoheal/releases
100 changes: 50 additions & 50 deletions src/inquire/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,68 @@ use crate::{report::logging::print_version, ALLOWED_CONNECTION_TYPES};
use getopts::Options;

pub struct OptionsList {
pub apprise_url: Option<String>,
pub connection_type: Option<String>,
pub stop_timeout: Option<String>,
pub interval: Option<String>,
pub start_delay: Option<String>,
pub interval: Option<String>,
pub webhook_key: Option<String>,
pub key_path: Option<String>,
pub log_all: bool,
pub monitor_all: bool,
pub tcp_host: Option<String>,
pub tcp_port: Option<String>,
pub stop_timeout: Option<String>,
pub tcp_timeout: Option<String>,
pub key_path: Option<String>,
pub apprise_url: Option<String>,
pub webhook_key: Option<String>,
pub webhook_url: Option<String>,
pub post_action: Option<String>,
pub log_all: bool,
pub monitor_all: bool,
}

pub fn get_opts(args: Vec<String>) -> OptionsList {
let program = args[0].clone();

// Establish usable arguments
let mut opts = Options::new();
opts.optopt("a", "apprise-url", "The apprise url", "<APPRISE_URL>");
opts.optopt(
"c",
"connection-type",
"One of local, socket, http, or ssl",
"<CONNECTION_TYPE>",
);
opts.optopt(
"s",
"stop-timeout",
"Time in seconds to wait for action to complete",
"<STOP_TIMEOUT>",
"d",
"start-delay",
"Time in seconds to wait for first check",
"<START_DELAY>",
);
opts.optflag("h", "help", "Print help");
opts.optopt(
"i",
"interval",
"Time in seconds to check health",
"<INTERVAL>",
);
opts.optopt(
"d",
"start-delay",
"Time in seconds to wait for first check",
"<START_DELAY>",
"j",
"webhook-key",
"The webhook json key string",
"<WEBHOOK_KEY>",
);
opts.optopt(
"k",
"key-path",
"The fully qualified path to requisite ssl PEM files",
"<KEY_PATH>",
);
opts.optflag(
"l",
"log-all",
"Enable logging of unhealthy containers where restart is disabled (WARNING, this could be chatty)",
);
opts.optflag(
"m",
"monitor-all",
"Enable monitoring off all containers that have a healthcheck",
);
opts.optopt(
"n",
Expand All @@ -59,44 +77,26 @@ pub fn get_opts(args: Vec<String>) -> OptionsList {
"The tcp port number of the Docker host (when -c http or ssl)",
"<TCP_PORT>",
);
opts.optopt(
"s",
"stop-timeout",
"Time in seconds to wait for action to complete",
"<STOP_TIMEOUT>",
);
opts.optopt(
"t",
"tcp-timeout",
"Time in seconds to wait for connection to complete",
"<TCP_TIMEOUT>",
);
opts.optopt(
"k",
"key-path",
"The fully qualified path to requisite ssl PEM files",
"<KEY_PATH>",
);
opts.optopt("a", "apprise-url", "The apprise url", "<APPRISE_URL>");
opts.optopt(
"j",
"webhook-key",
"The webhook json key string",
"<WEBHOOK_KEY>",
);
opts.optopt("w", "webhook-url", "The webhook url", "<WEBHOOK_URL>");
opts.optopt(
"a",
"P",
"post-action",
"The absolute path to a script that should be executed after container restart",
"<SCRIPT_PATH>",
);
opts.optflag(
"m",
"monitor-all",
"Enable monitoring off all containers that have a healthcheck",
);
opts.optflag(
"l",
"log-all",
"Enable logging of unhealthy containers where restart is disabled (WARNING, this could be chatty)",
);
opts.optflag("h", "help", "Print help");
opts.optflag("v", "version", "Print version information");
opts.optflag("V", "version", "Print version information");

let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Expand All @@ -108,7 +108,7 @@ pub fn get_opts(args: Vec<String>) -> OptionsList {
};

// Process matching arguments
if matches.opt_present("v") {
if matches.opt_present("V") {
print_version();
std::process::exit(0);
} else if matches.opt_present("h") {
Expand All @@ -133,19 +133,19 @@ pub fn get_opts(args: Vec<String>) -> OptionsList {
};

OptionsList {
apprise_url: matches.opt_str("a"),
connection_type: matches.opt_str("c"),
stop_timeout: matches.opt_str("s"),
interval: matches.opt_str("i"),
start_delay: matches.opt_str("d"),
interval: matches.opt_str("i"),
webhook_key: matches.opt_str("j"),
key_path: matches.opt_str("k"),
log_all: matches.opt_present("l"),
monitor_all: matches.opt_present("m"),
tcp_host: matches.opt_str("n"),
tcp_port: matches.opt_str("p"),
stop_timeout: matches.opt_str("s"),
tcp_timeout: matches.opt_str("t"),
key_path: matches.opt_str("k"),
apprise_url: matches.opt_str("a"),
webhook_key: matches.opt_str("j"),
webhook_url: matches.opt_str("w"),
post_action: matches.opt_str("a"),
log_all: matches.opt_present("l"),
monitor_all: matches.opt_present("m"),
post_action: matches.opt_str("P"),
}
}

0 comments on commit 226e361

Please sign in to comment.