mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-22 20:51:07 +01:00
Compare commits
14 Commits
0b4e8c5c6a
...
9f50c9e5b9
Author | SHA1 | Date | |
---|---|---|---|
9f50c9e5b9 | |||
135838173c | |||
a3e94497a9 | |||
19f368556e | |||
678f0fa999 | |||
4820f2468c | |||
d21c3b3072 | |||
26f9cbd49c | |||
ec331862ad | |||
03c04eadf7 | |||
ee1b2e0140 | |||
1c31f82f7c | |||
7cce98699c | |||
3a33c8b00f |
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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,9 +51,15 @@
|
|||||||
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:
|
||||||
|
@ -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
|
@ -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' %}
|
@ -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
|
@ -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
|
88
roles/storage/files/optimize.py
Normal file
88
roles/storage/files/optimize.py
Normal 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.")
|
||||||
|
|
@ -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:
|
||||||
|
@ -77,7 +77,6 @@
|
|||||||
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
|
||||||
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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}}
|
||||||
|
Loading…
Reference in New Issue
Block a user