Compare commits

..

14 Commits

12 changed files with 113 additions and 40 deletions

View File

@ -5,7 +5,7 @@
become: true become: true
roles: roles:
- role: update - role: update
when: execute_updates | bool when: mode_update | bool
- name: setup standard wireguard - name: setup standard wireguard
hosts: wireguard_server hosts: wireguard_server

View File

@ -10,6 +10,10 @@ backups_folder_path: "/Backups/" # Path to the backups folder
mode_reset: false # Cleans up all CyMaIS files. It's necessary to run to whole playbook and not particial roles when using this function. mode_reset: false # Cleans up all CyMaIS files. It's necessary to run to whole playbook and not particial roles when using this function.
mode_verbose: false # Prints well formated debug information mode_verbose: false # Prints well formated debug information
mode_test: false # Executes test routines instead of productive routines mode_test: false # Executes test routines instead of productive routines
mode_update: true # Executes updates
mode_backup: true # Activates the backup before the update procedure
mode_setup: false # Execute the setup and initializing procedures
# Server Tact Variables # Server Tact Variables
@ -60,9 +64,6 @@ path_system_lock_script: "{{path_administrator_scripts}}system-maintenanc
# Runtime Variables for Process Control # Runtime Variables for Process Control
activate_all_timers: false # Activates all timers, independend if the handlers had been triggered activate_all_timers: false # Activates all timers, independend if the handlers had been triggered
nginx_matomo_tracking: false # Activates matomo tracking on all html pages nginx_matomo_tracking: false # Activates matomo tracking on all html pages
execute_updates: true # Executes updates
force_backup_before_update: true # Activates the backup before the update procedure
# System maintenance Services # System maintenance Services
@ -108,13 +109,6 @@ nginx_upstreams_directory: "{{nginx_configuration_directory}}upstreams/"
## Docker Applications ## Docker Applications
### Enable Setup
setup_default: "false" # Pass CLI commands to execute the setup tasks for the different roles
setup_akaunting: "{{setup_default}}"
setup_mailu: "{{setup_default}}"
setup_listmonk: "{{setup_default}}"
setup_mastodon: "{{setup_default}}"
### Enable Central MariaDB ### Enable Central MariaDB
enable_central_database: true enable_central_database: true

View File

@ -12,18 +12,6 @@
- name: "include tasks nginx-docker-proxy-domain.yml" - name: "include tasks nginx-docker-proxy-domain.yml"
include_tasks: nginx-docker-proxy-domain.yml include_tasks: nginx-docker-proxy-domain.yml
- name: "stop container discourse_application"
command:
cmd: "docker stop discourse_application"
ignore_errors: true
when: mode_reset | bool
- name: "rm container discourse_application"
command:
cmd: "docker rm discourse_application"
ignore_errors: true
when: mode_reset | bool
- name: "cleanup central database from {{docker_compose_project_name}}_default network" - name: "cleanup central database from {{docker_compose_project_name}}_default network"
command: command:
cmd: "docker network disconnect discourse_default central-{{ database_type }}" cmd: "docker network disconnect discourse_default central-{{ database_type }}"
@ -36,7 +24,6 @@
- name: flush, to recreate discourse docker compose - name: flush, to recreate discourse docker compose
meta: flush_handlers meta: flush_handlers
when: enable_central_database | bool
- name: pull docker repository - name: pull docker repository
git: git:
@ -64,10 +51,16 @@
cmd: "docker network connect discourse_default central-{{ database_type }}" cmd: "docker network connect discourse_default central-{{ database_type }}"
when: enable_central_database | bool when: enable_central_database | bool
- name: "destroy container discourse_application"
command:
cmd: "./launcher destroy discourse_application"
chdir: "{{discourse_repository_directory}}"
ignore_errors: true
when: mode_reset | bool
- name: flush, to recreate discourse app - name: flush, to recreate discourse app
meta: flush_handlers meta: flush_handlers
when: enable_central_database | bool
- name: "remove central database from {{docker_compose_project_name}}_default" - name: "remove central database from {{docker_compose_project_name}}_default"
command: command:
cmd: "docker network disconnect discourse_default central-{{ database_type }}" cmd: "docker network disconnect discourse_default central-{{ database_type }}"

View File

@ -20,10 +20,10 @@
- name: flush docker service - name: flush docker service
meta: flush_handlers meta: flush_handlers
when: setup | bool when: mode_setup |bool
- name: setup routine for listmonk - name: setup routine for listmonk
command: command:
cmd: docker compose run -T --rm application sh -c "yes | ./listmonk --install" cmd: docker compose run -T --rm application sh -c "yes | ./listmonk --install"
chdir: "{{docker_compose_instance_directory}}" chdir: "{{docker_compose_instance_directory}}"
when: setup | bool when: mode_setup |bool

View File

@ -16,4 +16,6 @@ services:
{% include 'templates/docker-container-networks.yml.j2' %} {% include 'templates/docker-container-networks.yml.j2' %}
{% include 'templates/docker-container-depends-on-just-database.yml.j2' %} {% include 'templates/docker-container-depends-on-just-database.yml.j2' %}
{% include 'templates/docker-compose-volumes.yml.j2' %}
{% include 'templates/docker-compose-networks.yml.j2' %} {% include 'templates/docker-compose-networks.yml.j2' %}

View File

@ -64,11 +64,11 @@
- name: flush docker service - name: flush docker service
meta: flush_handlers meta: flush_handlers
when: setup | bool when: mode_setup |bool
- name: execute database migration - name: execute database migration
command: command:
cmd: "docker compose -p mailu exec admin flask mailu admin admin {{top_domain}} {{mailu_initial_root_password}}" cmd: "docker compose -p mailu exec admin flask mailu admin admin {{top_domain}} {{mailu_initial_root_password}}"
chdir: "{{docker_compose_instance_directory}}" chdir: "{{docker_compose_instance_directory}}"
ignore_errors: true ignore_errors: true
when: setup | bool when: mode_setup |bool

View File

@ -20,10 +20,10 @@
- name: flush docker service - name: flush docker service
meta: flush_handlers meta: flush_handlers
when: setup | bool when: mode_setup |bool
- name: setup routine for mastodon - name: setup routine for mastodon
command: command:
cmd: "docker-compose run --rm web bundle exec rails db:migrate" cmd: "docker-compose run --rm web bundle exec rails db:migrate"
chdir: "{{docker_compose_instance_directory}}" chdir: "{{docker_compose_instance_directory}}"
when: setup | bool when: mode_setup |bool

View File

@ -0,0 +1,88 @@
import subprocess
import os
import shutil
import argparse
def run_command(command):
""" Run a shell command and return its output """
return subprocess.check_output(command, shell=True).decode('utf-8').strip()
def stop_containers(containers):
"""Stop a list of containers."""
container_list = ' '.join(containers)
print(f"Stopping containers {container_list}...")
run_command(f"docker stop {container_list}")
def start_containers(containers):
"""Start a list of containers."""
container_list = ' '.join(containers)
print(f"Starting containers {container_list}...")
run_command(f"docker start {container_list}")
def is_database(image):
databases = {"postgres", "mariadb", "redis", "memcached"}
return any(database in image for database in databases)
def is_symbolic_link(file_path):
return os.path.islink(file_path)
def get_volume_path(volume):
return run_command(f"docker volume inspect --format '{{{{ .Mountpoint }}}}' {volume}")
def get_image(container):
return run_command(f"docker inspect --format='{{{{.Config.Image}}}}' {container}")
def pause_and_move(storage_path, volume, volume_path, containers):
stop_containers(containers)
# Create a new directory on the Storage
storage_volume_path = os.path.join(storage_path, volume)
os.makedirs(storage_volume_path, exist_ok=False)
# Move the data
for item in os.listdir(volume_path):
shutil.move(os.path.join(volume_path, item), storage_volume_path)
# Create a symbolic link
os.symlink(storage_volume_path, volume_path)
start_containers(containers)
def has_container_with_database(containers):
for container in containers:
# Get the image of the container
image = get_image(container)
if is_database(image):
return True
return False
if __name__ == "__main__":
# Argument parser setup
parser = argparse.ArgumentParser(description='Migrate Docker volumes to SSD or HDD based on container image.')
parser.add_argument('--ssd_path', type=str, required=True, help='Path to the SSD storage')
parser.add_argument('--hdd_path', type=str, required=True, help='Path to the HDD storage')
# Parse arguments
args = parser.parse_args()
# Set paths from arguments
ssd_path = args.ssd_path
hdd_path = args.hdd_path
# List all Docker volumes
volumes = run_command("docker volume ls -q").splitlines()
for volume in volumes:
containers = run_command(f"docker ps -q --filter volume={volume}").splitlines()
volume_path = get_volume_path(volume)
if is_symbolic_link(volume_path):
print(f"Skipped Volume {volume}. The storage path {volume_path} is a symbolic link.")
elif has_container_with_database(containers):
print(f"Safing volume {volume} on SSD.")
pause_and_move(ssd_path, volume, volume_path, containers)
else:
print(f"Safing volume {volume} on HDD.")
pause_and_move(hdd_path, volume, volume_path, containers)
print("Operation completed.")

View File

@ -2,7 +2,7 @@
systemd: systemd:
name: backup-docker-to-local-everything.service name: backup-docker-to-local-everything.service
state: started state: started
when: force_backup_before_update | bool when: mode_backup | bool
- name: create {{update_docker_script}} - name: create {{update_docker_script}}
copy: copy:

View File

@ -77,8 +77,7 @@
vars: vars:
domain: "{{domain_mailu}}" domain: "{{domain_mailu}}"
http_port: 8007 http_port: 8007
setup: "{{ setup_mailu }}"
- name: setup elk hosts - name: setup elk hosts
hosts: elk hosts: elk
become: true become: true
@ -98,7 +97,6 @@
domains: "{{ [domain] + domains_mastodon_alternates }}" domains: "{{ [domain] + domains_mastodon_alternates }}"
http_port: 8009 http_port: 8009
stream_port: 4001 stream_port: 4001
setup: "{{ setup_mastodon }}"
- name: setup pixelfed hosts - name: setup pixelfed hosts
hosts: pixelfed hosts: pixelfed
@ -190,7 +188,6 @@
vars: vars:
domain: "{{domain_listmonk}}" domain: "{{domain_listmonk}}"
http_port: 8019 http_port: 8019
setup: "{{ setup_listmonk }}"
- name: setup discourse - name: setup discourse
hosts: discourse hosts: discourse
@ -249,7 +246,6 @@
vars: vars:
domain: "{{domain_akaunting}}" domain: "{{domain_akaunting}}"
http_port: 8025 http_port: 8025
setup: "{{ setup_akaunting }}"
# Native Webserver Roles # Native Webserver Roles
- name: setup nginx-homepages - name: setup nginx-homepages

View File

@ -1,7 +1,7 @@
# This template needs to be included in docker-compose.yml, which depend on a mariadb database # This template needs to be included in docker-compose.yml, which depend on a mariadb database
{% if not enable_central_database | bool %} {% if not enable_central_database | bool %}
database: database:
container_name: {{docker_compose_project_name}}-mariadb container_name: {{docker_compose_project_name}}-database
logging: logging:
driver: journald driver: journald
image: mariadb image: mariadb

View File

@ -2,7 +2,7 @@
{% if not enable_central_database | bool %} {% if not enable_central_database | bool %}
database: database:
image: postgres:{{database_version}}-alpine image: postgres:{{database_version}}-alpine
container_name: {{docker_compose_project_name}}-postgres container_name: {{docker_compose_project_name}}-database
environment: environment:
- POSTGRES_PASSWORD={{database_password}} - POSTGRES_PASSWORD={{database_password}}
- POSTGRES_USER={{database_username}} - POSTGRES_USER={{database_username}}