GitXplorerGitXplorer
a

docker-watchdog

public
7 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
afad6ba020c4924ddf0e289b21c2604fac19ad55

Bump version to 0.0.5

aadamrehn committed 6 years ago
Unverified
0b7856fbd7b99c712dc1f2ff9bf20e322bec2408

Explicitly identify the root user by UID under macOS and Linux

aadamrehn committed 6 years ago
Unverified
adae387bcd6df67a13326c6ae089a9fb038bb0fd

Flush stdout before starting the sampling loop

aadamrehn committed 6 years ago
Unverified
865304011b0d2eda17b44f23b59c4908e4859158

Bump version to 0.0.4

aadamrehn committed 6 years ago
Unverified
e5e69322b20814707d7d2553ec0b52216be6d612

Set service description under macOS and Linux

aadamrehn committed 6 years ago
Unverified
a814f24ae3eeba41aff43741600644083c001768

Enable installed service in Debian server script

aadamrehn committed 6 years ago

README

The README file for this repository.

Docker Idle Watchdog

The docker-watchdog Python package provides a background service that monitors Docker container hosts for periods of inactivity and performs an automatic shutdown of the host after a predefined idle threshold is reached. In a similar manner to the shutdown-if-idle package, the intended use case is the automatic shutdown of cloud VMs that have been started on demand as part of a Continuous Integration (CI) pipeline, albeit with a focus on Docker container hosts.

The key features of the package include:

  • Supports Windows, macOS, and Linux
  • Provides easy service installation under all supported operating systems
  • Takes cloud provider billing granularity into account to ensure shutdown decisions are cost-effective

Contents

Installation

Requirements

The docker-watchdog package requires the following:

  • Python 3.5 or newer
  • Under macOS and Linux, the pleaserun Ruby gem needs to be installed to perform service installation

Package installation

To install the docker-watchdog Python package itself, simply run:

pip3 install docker-watchdog

(You may need to prefix this command with sudo under macOS and Linux.)

Once the package is installed, you can run the watchdog via either of these commands:

# Uses the wrapper generated by pip
docker-watchdog

# Invokes the package directly via the Python interpreter
python3 -m docker_watchdog

Service installation

To install the startup service for docker-watchdog, ensure you have any necessary dependencies installed and run the following command with elevated privileges:

docker-watchdog --install

The background service will then start automatically the next time the host system boots up.

Installation scripts for cloud servers

To simplify the setup process for cloud servers, the scripts directory contains installation scripts for common Docker container host platforms. The scripts automatically install docker-watchdog and its dependencies, and register the docker-watchdog startup service.

Scripts are provided for the following platforms:

  • Windows Server: scripts/install_windows_server.ps1

    Installs the Chocolatey package manager, uses Chocolatey to install Python and docker-watchdog, and registers the docker-watchdog startup service.

    To use this script, run the following command from an elevated PowerShell prompt:

    Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/adamrehn/docker-watchdog/master/scripts/install_windows_server.ps1'))
  • Debian-based Linux distros: scripts/install_debian.sh

    Installs Python, Ruby, pleaserun, and docker-watchdog, and registers the docker-watchdog startup service.

    To use this script, run the following command with root priveleges:

    curl -fsSL 'https://raw.githubusercontent.com/adamrehn/docker-watchdog/master/scripts/install_debian.sh' | bash

Configuration

The watchdog can be configured either via a JSON configuration file or via environment variables. These two methods can also be used together, in which case values from the configuration file will take precedence over values from environment variables. Any settings for which a value has not been specified will fallback to using a sane default.

The location of the JSON configuration file is based on the operating system and runtime environment:

  • Under Windows: %APPDATA%\docker-watchdog\config.json
  • Under macOS and Linux:
    • If running as a non-root user: $HOME/.config/docker-watchdog/config.json
    • If running as the root user: /etc/docker-watchdog/config.json

The available configuration settings are as follows:

JSON Key Environment Variable Default Description
sleep DOCKER_WATCHDOG_SLEEP_INTERVAL 60 Specifies the interval (in seconds) to sleep for between sampling runs.
timeout DOCKER_WATCHDOG_IDLE_TIMEOUT 600 Specifies the period of inactivity (in seconds) required to consider the system idle.
billing DOCKER_WATCHDOG_BILLING_GRANULARITY 0 Specifies the billing granularity (in seconds) if the host is a cloud VM, or zero otherwise.
percentage DOCKER_WATCHDOG_EFFECTIVE_PERCENTAGE 0.9 Specifies the minimum percentage (0.0 to 1.0) of the current billing unit that must have elapsed to consider a shutdown to be cost-effective.

Legal

Copyright © 2019, Adam Rehn. Licensed under the MIT License, see the file LICENSE for details.

Development of this package was funded by Deepdrive, Inc.