computer-playbook/roles/sys-ctl-rpr-docker-hard
Kevin Veen-Birkenbach 9756a0f75f
Extend repair scripts with env-file support and unit tests
- Added detect_env_file() to both sys-ctl-rpr-docker-soft and sys-ctl-rpr-docker-hard
  * prefer .env, fallback to .env/env
  * append --env-file parameter automatically
- Refactored soft script to use compose_cmd() for consistent command building
- Adjusted error recovery path in soft script to also respect env-file
- Extended unit tests for soft script to cover env-file priority and restart commands
- Added new unit tests for hard script verifying env-file priority, cwd handling,
  and --only filter logic

Ref: https://chatgpt.com/share/68ad7b30-7510-800f-8172-56f03a2f40f5
2025-08-26 11:15:59 +02:00
..

Docker Auto Restart

Description

This role automates the restart process for Docker Compose instances within a specified directory. It deploys a Python script that checks for the presence of docker-compose.yml files and restarts the associated services—using a hard restart for certain directories if needed.

Overview

Optimized for containerized environments, this role:

  • Sets up the necessary directories and scripts for restarting Docker Compose instances.
  • Configures a systemd service (and optionally a timer) to execute the restart script.
  • Handles both standard restarts and hard restarts for specific containers (e.g., for Mailu).

Purpose

The primary purpose of this role is to ensure that all Docker Compose services are restarted consistently, resolving issues that may arise from partial restarts. This helps maintain overall service stability and minimizes downtime.

Features

  • Automated Detection: Scans a specified parent directory for docker-compose.yml files.
  • Service Restart: Executes a Python script to restart Docker services via docker-compose.
  • Conditional Hard Restart: Applies a hard restart procedure for specific directories (e.g., Mailu).
  • Systemd Integration: Configures a systemd service and optionally a timer for scheduled restarts.

Context

This role was implemented to address the classic issue: "Have you tried turning it off and on again?". The problem initially arose with the fetchmail container in Mailu, which fails if only some containers, and not the full docker-compose composition, are restarted.

Credits 📝

This role was developed with the assistance of ChatGPT, including insights and optimizations from this conversation. Special thanks for providing guidance on error handling, Ansible best practices, and Python integration.