mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-25 14:11:03 +01:00
Compare commits
No commits in common. "2e3e54f11f2eb3c11279c652587e66de2edea9f5" and "e2ee58e6a5c4394826a2f67f295a13ceccf987ec" have entirely different histories.
2e3e54f11f
...
e2ee58e6a5
@ -4,11 +4,10 @@
|
|||||||
|
|
||||||
randomized_delay_sec: "15min"
|
randomized_delay_sec: "15min"
|
||||||
|
|
||||||
on_calendar_btrfs_health_check: "*-*-* 00:00:00"
|
on_calendar_btrfs_health_check: "*-*-* 00:00:00"
|
||||||
on_calendar_journalctl_health_check: "*-*-* 00:00:00"
|
on_calendar_journalctl_health_check: "*-*-* 00:00:00"
|
||||||
on_calendar_disc_space_check: "*-*-* 06,12,18,00:00:00"
|
on_calendar_disc_space_check: "*-*-* 06,12,18,00:00:00"
|
||||||
on_calendar_docker_health_check: "*-*-* 09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00,01,02:00:00"
|
on_calendar_docker_health_check: "*-*-* 09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00,01,02:00:00"
|
||||||
on_calendar_nginx_health_check: "*-*-* 09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,00,01,02:15:00"
|
|
||||||
|
|
||||||
on_calendar_backups_cleanup: "*-*-* 06,12,18,00:30:00"
|
on_calendar_backups_cleanup: "*-*-* 06,12,18,00:30:00"
|
||||||
on_calendar_free_disc_space: "*-*-* 07,13,19,01:30:00"
|
on_calendar_free_disc_space: "*-*-* 07,13,19,01:30:00"
|
||||||
|
@ -11,8 +11,6 @@ PEERTUBE_DB_HOSTNAME=database
|
|||||||
PEERTUBE_WEBSERVER_HOSTNAME={{domain}}
|
PEERTUBE_WEBSERVER_HOSTNAME={{domain}}
|
||||||
PEERTUBE_TRUST_PROXY=["127.0.0.1", "loopback"]
|
PEERTUBE_TRUST_PROXY=["127.0.0.1", "loopback"]
|
||||||
|
|
||||||
PEERTUBE_SECRET={{peertube_secret}}
|
|
||||||
|
|
||||||
# E-mail configuration
|
# E-mail configuration
|
||||||
PEERTUBE_SMTP_USERNAME={{system_email_username}}
|
PEERTUBE_SMTP_USERNAME={{system_email_username}}
|
||||||
PEERTUBE_SMTP_PASSWORD={{system_email_password}}
|
PEERTUBE_SMTP_PASSWORD={{system_email_password}}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# health-nginx
|
|
||||||
|
|
||||||
Sends a health report for nginx configurations. This role was created with the help of ChatGPT. The conversation you will find [here](https://chat.openai.com/share/4033be29-12a6-40a3-bf3c-fc5d57dba8cb).
|
|
||||||
|
|
||||||
## see
|
|
||||||
- https://nginx.org/en/docs/
|
|
||||||
- https://docs.ansible.com/ansible/latest/modules/uri_module.html
|
|
@ -1,53 +0,0 @@
|
|||||||
import os
|
|
||||||
import requests
|
|
||||||
import sys
|
|
||||||
import re
|
|
||||||
|
|
||||||
# Define the path to the nginx configuration directory
|
|
||||||
config_path = '/etc/nginx/conf.d/'
|
|
||||||
|
|
||||||
# Initialize the error counter
|
|
||||||
error_counter = 0
|
|
||||||
|
|
||||||
# Regex pattern to match domain.tld or subdomain.domain.tld
|
|
||||||
pattern = re.compile(r"^(?:[\w-]+\.)?[\w-]+\.[\w-]+\.conf$")
|
|
||||||
|
|
||||||
# Iterate over each file in the configuration directory
|
|
||||||
for filename in os.listdir(config_path):
|
|
||||||
if filename.endswith('.conf') and pattern.match(filename):
|
|
||||||
# Extract the domain and subdomain from the filename
|
|
||||||
name = filename.replace('.conf', '')
|
|
||||||
parts = name.split('.')
|
|
||||||
|
|
||||||
# Prepare the URL and expected status codes
|
|
||||||
url = f"http://{name}"
|
|
||||||
|
|
||||||
# Determine expected status codes based on subdomain
|
|
||||||
if len(parts) == 3 and parts[0] == 'www':
|
|
||||||
expected_statuses = [200,301]
|
|
||||||
elif len(parts) == 3 and parts[0] == 's':
|
|
||||||
expected_statuses = [403]
|
|
||||||
elif len(parts) <= 3:
|
|
||||||
# For domain.tld where no specific subdomain is present
|
|
||||||
expected_statuses = [200, 301]
|
|
||||||
else:
|
|
||||||
# Skip files that don't match the schema
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Send a HEAD request to get only the response header
|
|
||||||
response = requests.head(url, allow_redirects=True)
|
|
||||||
|
|
||||||
# Check if the status code matches the expected statuses
|
|
||||||
if response.status_code in expected_statuses:
|
|
||||||
print(f"{name}: ok")
|
|
||||||
else:
|
|
||||||
print(f"{name}: error")
|
|
||||||
error_counter += 1
|
|
||||||
except requests.RequestException as e:
|
|
||||||
# Handle exceptions for requests like connection errors
|
|
||||||
print(f"{name}: error due to {e}")
|
|
||||||
error_counter += 1
|
|
||||||
|
|
||||||
# Exit the script with the number of errors as the exit code
|
|
||||||
sys.exit(error_counter)
|
|
@ -1,12 +0,0 @@
|
|||||||
- name: "reload health-nginx.service"
|
|
||||||
systemd:
|
|
||||||
name: health-nginx.service
|
|
||||||
enabled: yes
|
|
||||||
daemon_reload: yes
|
|
||||||
|
|
||||||
- name: "restart health-nginx.timer"
|
|
||||||
systemd:
|
|
||||||
name: health-nginx.timer
|
|
||||||
state: restarted
|
|
||||||
enabled: yes
|
|
||||||
daemon_reload: yes
|
|
@ -1,3 +0,0 @@
|
|||||||
dependencies:
|
|
||||||
- python-pip
|
|
||||||
- systemd_notifier
|
|
@ -1,29 +0,0 @@
|
|||||||
- name: Install required Python modules
|
|
||||||
pacman:
|
|
||||||
name: python-requests
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: "create {{ nginx_health_check_folder }}"
|
|
||||||
file:
|
|
||||||
path: "{{ nginx_health_check_folder }}"
|
|
||||||
state: directory
|
|
||||||
mode: 0755
|
|
||||||
|
|
||||||
- name: create health-nginx.py
|
|
||||||
copy:
|
|
||||||
src: health-nginx.py
|
|
||||||
dest: "{{ nginx_health_check_folder }}health-nginx.py"
|
|
||||||
|
|
||||||
- name: create health-nginx.service
|
|
||||||
template:
|
|
||||||
src: health-nginx.service.j2
|
|
||||||
dest: /etc/systemd/system/health-nginx.service
|
|
||||||
notify: reload health-nginx.service
|
|
||||||
|
|
||||||
- name: create health-nginx.timer
|
|
||||||
template:
|
|
||||||
src: health-nginx.timer.j2
|
|
||||||
dest: "/etc/systemd/system/health-nginx.timer"
|
|
||||||
register: health_nginx_timer
|
|
||||||
changed_when: health_nginx_timer.changed or activate_all_timers | default(false) | bool
|
|
||||||
notify: restart health-nginx.timer
|
|
@ -1,7 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Check nginx configuration status
|
|
||||||
OnFailure=systemd-notifier@%n.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
ExecStart=/usr/bin/python3 {{ nginx_health_check_folder }}health-nginx.py
|
|
@ -1,10 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=starts health-nginx.service
|
|
||||||
|
|
||||||
[Timer]
|
|
||||||
OnCalendar={{ on_calendar_nginx_health_check }}
|
|
||||||
RandomizedDelaySec={{ randomized_delay_sec }}
|
|
||||||
Persistent=false
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=timers.target
|
|
@ -1 +0,0 @@
|
|||||||
nginx_health_check_folder: "{{ path_administrator_scripts }}health-nginx/"
|
|
@ -1,2 +0,0 @@
|
|||||||
dependencies:
|
|
||||||
- health-nginx
|
|
Loading…
Reference in New Issue
Block a user