From 3aa70154071e4f09788e602e4e110fda16c1806e Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 22 Sep 2019 23:19:53 +0200 Subject: [PATCH] remove old mirror-health files in roles --- .../roles/files/mirror_health/mirror-health | 76 ------------------- modules/roles/manifests/mirror_health.pp | 38 ---------- .../roles/templates/mirror-health.service.erb | 26 ------- 3 files changed, 140 deletions(-) delete mode 100755 modules/roles/files/mirror_health/mirror-health delete mode 100644 modules/roles/manifests/mirror_health.pp delete mode 100644 modules/roles/templates/mirror-health.service.erb diff --git a/modules/roles/files/mirror_health/mirror-health b/modules/roles/files/mirror_health/mirror-health deleted file mode 100755 index bbd4c2787..000000000 --- a/modules/roles/files/mirror_health/mirror-health +++ /dev/null @@ -1,76 +0,0 @@ -#! /usr/bin/python3 - -import os -import requests -import time -import calendar -import logging -import subprocess -from email.utils import parsedate -logging.basicConfig(level=logging.INFO) - -HOSTS = os.environ['MIRROR_CHECK_HOSTS'].split() -OUTPUT_DIR = "/run/dsa-mirror-health-{}".format(os.environ['MIRROR_CHECK_SERVICE']) -HEALTH_FILE = os.path.join(OUTPUT_DIR, "health") -URL = os.environ['MIRROR_CHECK_URL'] -HEALTH_CHECK_URL = os.environ['MIRROR_CHECK_HEALTH_URL'] -INTERVAL = int(os.environ.get('MIRROR_CHECK_INTERVAL', '60')) - -def retrieve_from_host(host, url): - proxies = { - 'http': 'http://{}:80'.format(host), - 'https': 'http://{}:443'.format(host), - } - headers = {'User-Agent': 'mirror-health'} - return requests.get(url, headers=headers, timeout=5, proxies=proxies, allow_redirects=False) - -def last_modified(response): - lm = 0 - if response.status_code == 200 and response.headers.get('last-modified'): - lm = calendar.timegm(parsedate(response.headers['last-modified'])) - return lm - -def healthy(response): - if response.status_code == 200: - return True - return False - -def check_shutdown(): - if subprocess.call(['dsa-is-shutdown-scheduled']) == 0: - logging.info("considering myself unhealthy, shutdown scheduled") - return False - return True - -def check_uptodate(): - latest_ts = 0 - for host in HOSTS: - try: - lm = last_modified(retrieve_from_host(host, URL)) - logging.debug("lm for host %s: %s", host, lm) - if healthy(retrieve_from_host(host, HEALTH_CHECK_URL)): - latest_ts = max(latest_ts, lm) - except (requests.exceptions.ProxyError, requests.exceptions.ReadTimeout, requests.exceptions.ConnectTimeout, requests.exceptions.ConnectionError): - pass - try: - local_lm = last_modified(retrieve_from_host('localhost', URL)) - except (requests.exceptions.ProxyError, requests.exceptions.ReadTimeout, requests.exceptions.ConnectTimeout, requests.exceptions.ConnectionError): - return False - logging.debug("lm for localhost: %s", local_lm) - if local_lm < latest_ts: - logging.info("considering myself unhealthy my ts=%s latest_ts=%s", local_lm, latest_ts) - return False - return True - -while True: - start = time.time() - if check_shutdown() and check_uptodate(): - logging.info("considering myself healthy") - open(HEALTH_FILE, 'w').write("OK") - else: - try: - os.remove(HEALTH_FILE) - except OSError: - pass - sleep_time = start + INTERVAL - time.time() - logging.debug("sleeping for %d seconds", sleep_time) - time.sleep(sleep_time) diff --git a/modules/roles/manifests/mirror_health.pp b/modules/roles/manifests/mirror_health.pp deleted file mode 100644 index d4d0d625e..000000000 --- a/modules/roles/manifests/mirror_health.pp +++ /dev/null @@ -1,38 +0,0 @@ -define roles::mirror_health ( - $check_hosts = [], - $check_service = '', - $url = '', - $health_url = '', - $check_interval = 60, -) { - ensure_packages(['python3-requests'], { ensure => 'installed' }) - -# if !defined(File['/usr/local/sbin/mirror-health']) { -# file { '/usr/local/sbin/mirror-health': -# source => 'puppet:///modules/roles/mirror_health/mirror-health', -# owner => 'root', -# group => 'root', -# mode => '0555', -# notify => Service["mirror-health-${check_service}"], -# } -# } - - file { "/etc/systemd/system/mirror-health-${check_service}.service": - owner => 'root', - group => 'root', - mode => '0444', - content => template('roles/mirror-health.service.erb'), - notify => [Exec['systemctl daemon-reload'], Service["mirror-health-${check_service}"]], - } - - file { "/etc/systemd/system/multi-user.target.wants/mirror-health-${check_service}.service": - ensure => 'link', - target => "../mirror-health-${check_service}.service", - notify => Exec['systemctl daemon-reload'], - } - - service { "mirror-health-${check_service}": - require => Exec['systemctl daemon-reload'], - ensure => running, - } -} diff --git a/modules/roles/templates/mirror-health.service.erb b/modules/roles/templates/mirror-health.service.erb deleted file mode 100644 index 60d9dcd72..000000000 --- a/modules/roles/templates/mirror-health.service.erb +++ /dev/null @@ -1,26 +0,0 @@ -## -## THIS FILE IS UNDER PUPPET CONTROL. DON'T EDIT IT HERE. -## USE: git clone git+ssh://$USER@puppet.debian.org/srv/puppet.debian.org/git/dsa-puppet.git -## - -[Unit] -Description=Mirror health checking <%= @check_service %> - -[Service] -ExecStart=/usr/local/sbin/mirror-health -RuntimeDirectory=dsa-mirror-health-<%= @check_service %> -ProtectSystem=full -ProtectHome=read-only -PrivateTmp=true -User=nobody -Group=nogroup -Restart=always - -Environment="MIRROR_CHECK_SERVICE=<%= @check_service %>" -Environment="MIRROR_CHECK_URL=<%= @url %>" -Environment="MIRROR_CHECK_HEALTH_URL=<%= @health_url %>" -Environment="MIRROR_CHECK_HOSTS=<%= @check_hosts.join ' ' %>" -Environment="MIRROR_CHECK_INTERVAL=<%= @check_interval %>" - -[Install] -WantedBy=multi-user.target -- 2.20.1