Compare commits

..

No commits in common. "9f50c9e5b934f3e70d826e2e1d6d9e115dcba5d2" and "0b4e8c5c6afeaa15c9568490504347e4409a2625" have entirely different histories.

12 changed files with 40 additions and 113 deletions

View File

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

View File

@ -10,10 +10,6 @@ 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
@ -64,6 +60,9 @@ 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
@ -109,6 +108,13 @@ 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,6 +12,18 @@
- 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 }}"
@ -24,6 +36,7 @@
- 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:
@ -51,16 +64,10 @@
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: mode_setup |bool when: 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: mode_setup |bool when: setup | bool

View File

@ -16,6 +16,4 @@ 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: mode_setup |bool when: 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: mode_setup |bool when: setup | bool

View File

@ -20,10 +20,10 @@
- name: flush docker service - name: flush docker service
meta: flush_handlers meta: flush_handlers
when: mode_setup |bool when: 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: mode_setup |bool when: setup | bool

View File

@ -1,88 +0,0 @@
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: mode_backup | bool when: force_backup_before_update | bool
- name: create {{update_docker_script}} - name: create {{update_docker_script}}
copy: copy:

View File

@ -77,7 +77,8 @@
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
@ -97,6 +98,7 @@
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
@ -188,6 +190,7 @@
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
@ -246,6 +249,7 @@
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}}-database container_name: {{docker_compose_project_name}}-mariadb
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}}-database container_name: {{docker_compose_project_name}}-postgres
environment: environment:
- POSTGRES_PASSWORD={{database_password}} - POSTGRES_PASSWORD={{database_password}}
- POSTGRES_USER={{database_username}} - POSTGRES_USER={{database_username}}