From d55e2e486bed4defedc07181e199dc4f76833e30 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sun, 4 Sep 2022 12:47:18 -0400 Subject: [PATCH] feat: deluge service (#3) --- .gitignore | 2 ++ deluge/docker-compose.yml | 15 +++++++++ deluge/script/bootstrap | 3 ++ deluge/tasks.py | 64 +++++++++++++++++++++++++++++++++++++++ plex/tasks.py | 2 +- tasks.py | 2 ++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 deluge/docker-compose.yml create mode 100644 deluge/script/bootstrap create mode 100644 deluge/tasks.py diff --git a/.gitignore b/.gitignore index 1bdb690..fc0c6e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ spadinaistan.venv +deluge/config +deluge/downloads **/healthcheck.json **/config.json diff --git a/deluge/docker-compose.yml b/deluge/docker-compose.yml new file mode 100644 index 0000000..3eb946b --- /dev/null +++ b/deluge/docker-compose.yml @@ -0,0 +1,15 @@ +version: "2.1" +services: + deluge: + image: lscr.io/linuxserver/deluge:latest + container_name: deluge + environment: + - TZ=America/Toronto + volumes: + - ./config:/config + - ./downloads:/downloads + ports: + - 8112:8112 + - 6881:6881 + - 6881:6881/udp + restart: unless-stopped diff --git a/deluge/script/bootstrap b/deluge/script/bootstrap new file mode 100644 index 0000000..2a63c50 --- /dev/null +++ b/deluge/script/bootstrap @@ -0,0 +1,3 @@ +#!/bin/bash + +mkdir ./{config,downloads} diff --git a/deluge/tasks.py b/deluge/tasks.py new file mode 100644 index 0000000..9a1a26a --- /dev/null +++ b/deluge/tasks.py @@ -0,0 +1,64 @@ +import invoke +import pathlib +import typing +import json + +PATH = pathlib.Path(__file__).parent + + +@invoke.task() +def start(ctx): + with ctx.cd(PATH): + ctx.run("docker-compose up -d") + + +@invoke.task() +def stop(ctx): + with ctx.cd(PATH): + ctx.run("docker-compose down") + + +@invoke.task() +def restart(ctx): + with ctx.cd(PATH): + ctx.run("docker-compose restart") + + +@invoke.task() +def healthcheck(ctx, as_json=False): + report = { + "containers_running": False, + } + + with ctx.cd(PATH): + healthy = True + # Check that the container is running + running_containers = ( + ctx.run("docker-compose ps --services --status running", hide=True) + .stdout.strip() + .split() + ) + + if "deluge" in running_containers: + print("✅ Deluge container is running!") + report["containers_running"] = True + else: + print("❌ Deluge is not running, use inv deluge.start.") + healthy = False + + if healthy: + print("✅ Deluge is healthy!") + else: + print("❌ Deluge has problems") + + if as_json: + with open(pathlib.Path(PATH, "healthcheck.json"), "w") as outfile: + outfile.write(json.dumps(report)) + + +ns = invoke.Collection("deluge") + +ns.add_task(start) +ns.add_task(restart) +ns.add_task(stop) +ns.add_task(healthcheck) diff --git a/plex/tasks.py b/plex/tasks.py index fdc8067..616e585 100644 --- a/plex/tasks.py +++ b/plex/tasks.py @@ -120,7 +120,7 @@ def healthcheck(ctx, as_json=False): print("❌ Plex has problems") if as_json: - with open(pathlib.Path(PATH, 'healthcheck.json'), 'w') as outfile: + with open(pathlib.Path(PATH, "healthcheck.json"), "w") as outfile: outfile.write(json.dumps(report)) diff --git a/tasks.py b/tasks.py index 5f5685c..3fda757 100644 --- a/tasks.py +++ b/tasks.py @@ -1,7 +1,9 @@ import invoke import plex.tasks +import deluge.tasks ns = invoke.Collection() ns.add_collection(plex.tasks.ns) +ns.add_collection(deluge.tasks.ns)