Package: docker-watchdog
Docker Idle WatchdogThe 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 theshutdown-if-idlepackage, 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 LinuxProvides easy service installation under all supported operating systemsTakes cloud provider billing granularity into account to ensure shutdown decisions are cost-effectiveContentsInstallationRequirementsPackage installationService installationInstallation scripts for cloud serversConfigurationLegalInstallationRequirementsThe docker-watchdog package requires the following:Python 3.5 or newerUnder macOS and Linux, thepleaserunRuby gem needs to be installed to perform service installationPackage installationTo install the docker-watchdog Python package itself, simply run:pip3 install docker-watchdog(You may need to prefix this command withsudounder macOS and Linux.)Once the package is installed, you can run the watchdog via either of these commands:# Uses the wrapper generated by pipdocker-watchdog# Invokes the package directly via the Python interpreterpython3-mdocker_watchdogService installationTo install the startup service for docker-watchdog, ensure you have anynecessary dependenciesinstalled and run the following command with elevated privileges:docker-watchdog --installThe background service will then start automatically the next time the host system boots up.Installation scripts for cloud serversTo simplify the setup process for cloud servers, thescriptsdirectory 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.ps1Installs theChocolateypackage 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-ExecutionPolicyBypass-ScopeProcess-Force;iex((New-ObjectSystem.Net.WebClient).DownloadString('https://raw.githubusercontent.com/adamrehn/docker-watchdog/master/scripts/install_windows_server.ps1'))Debian-based Linux distros:scripts/install_debian.shInstalls 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'|bashConfigurationThe 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.jsonUnder macOS and Linux:If running as a non-root user:$HOME/.config/docker-watchdog/config.jsonIf running as the root user:/etc/docker-watchdog/config.jsonThe available configuration settings are as follows:JSON KeyEnvironment VariableDefaultDescriptionsleepDOCKER_WATCHDOG_SLEEP_INTERVAL60Specifies the interval (in seconds) to sleep for between sampling runs.timeoutDOCKER_WATCHDOG_IDLE_TIMEOUT600Specifies the period of inactivity (in seconds) required to consider the system idle.billingDOCKER_WATCHDOG_BILLING_GRANULARITY0Specifies the billing granularity (in seconds) if the host is a cloud VM, or zero otherwise.percentageDOCKER_WATCHDOG_EFFECTIVE_PERCENTAGE0.9Specifies 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.LegalCopyright © 2019, Adam Rehn. Licensed under the MIT License, see the fileLICENSEfor details.Development of this package was funded byDeepdrive, Inc.