From 68afdda80249b06c13cc7e9b861b774043009430 Mon Sep 17 00:00:00 2001 From: Dmytro Galushko Date: Sat, 23 Mar 2024 12:03:40 +0200 Subject: [PATCH] Add more then 2 storages --- .../docker-compose/docker-compose-media.yml | 1 + .../docker-compose-torrent-low.yml | 23 ++++++++++++ .../examples/etc/systemd/services/bot.service | 2 +- .../etc/systemd/services/create_services.sh | 9 +++++ .../services/media-server-down.service | 2 +- .../systemd/services/torrent-low-down.service | 14 +++++++ .../systemd/services/torrent-low-pull.service | 14 +++++++ .../etc/systemd/services/torrent-low.service | 15 ++++++++ torrent/src/main/resources/scripts/run.sh | 37 +++++++++++-------- 9 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 config/examples/docker-compose/docker-compose-torrent-low.yml create mode 100644 config/examples/etc/systemd/services/torrent-low-down.service create mode 100644 config/examples/etc/systemd/services/torrent-low-pull.service create mode 100644 config/examples/etc/systemd/services/torrent-low.service diff --git a/config/examples/docker-compose/docker-compose-media.yml b/config/examples/docker-compose/docker-compose-media.yml index 7200db6..9d81256 100644 --- a/config/examples/docker-compose/docker-compose-media.yml +++ b/config/examples/docker-compose/docker-compose-media.yml @@ -14,5 +14,6 @@ services: - ./workdir/mediadata:/movies/1 - ./workdir/mediadata_hdd/mediadata:/movies/2 - ./workdir/mediadata_morhun:/movies/3 + - ./workdir/mediadata_hdd/low_quality:/movies/4 restart: unless-stopped network_mode: host \ No newline at end of file diff --git a/config/examples/docker-compose/docker-compose-torrent-low.yml b/config/examples/docker-compose/docker-compose-torrent-low.yml new file mode 100644 index 0000000..b9128c6 --- /dev/null +++ b/config/examples/docker-compose/docker-compose-torrent-low.yml @@ -0,0 +1,23 @@ +version: '3.7' + +services: + transmission_low: + image: lscr.io/linuxserver/transmission:latest + container_name: "transmission_low" + environment: + - PUID=1000 + - PGID=1000 + - TZ=Etc/UTC + volumes: + - ./workdir/config/transmission_low:/config + - ./workdir/mediadata_hdd/low_quality:/downloads/complete + - ./workdir/config/files_from_telegram_low:/watch + ports: + - 9094:9091 + - 51416:51413 + - 51416:51413/udp + networks: + torrent_network_low: +networks: + torrent_network_low: + driver: bridge diff --git a/config/examples/etc/systemd/services/bot.service b/config/examples/etc/systemd/services/bot.service index 0a983fd..dfbf02e 100644 --- a/config/examples/etc/systemd/services/bot.service +++ b/config/examples/etc/systemd/services/bot.service @@ -9,7 +9,7 @@ RemainAfterExit=yes WorkingDirectory=/home/dima/media ExecStart=/usr/bin/docker-compose -f docker-compose-bot.yml up ExecStop=/usr/bin/docker-compose -f docker-compose-bot.yml down -TimeoutStartSec=0 +TimeoutStartSec=0999 [Install] WantedBy=default.target diff --git a/config/examples/etc/systemd/services/create_services.sh b/config/examples/etc/systemd/services/create_services.sh index 0ade551..59538b4 100644 --- a/config/examples/etc/systemd/services/create_services.sh +++ b/config/examples/etc/systemd/services/create_services.sh @@ -16,6 +16,9 @@ systemctl stop torrent-pull.service systemctl stop torrent-hdd.service systemctl stop torrent-hdd-down.service systemctl stop torrent-hdd-pull.service +systemctl stop torrent-low.service +systemctl stop torrent-low-down.service +systemctl stop torrent-low-pull.service systemctl stop mount-hdd.service systemctl stop mount-smb.service @@ -35,6 +38,9 @@ systemctl disable torrent-pull.service systemctl disable torrent-hdd.service systemctl disable torrent-hdd-down.service systemctl disable torrent-hdd-pull.service +systemctl disable torrent-low.service +systemctl disable torrent-low-down.service +systemctl disable torrent-low-pull.service systemctl disable mount-hdd.service systemctl disable mount-smb.service @@ -56,5 +62,8 @@ systemctl enable torrent-pull.service systemctl enable torrent-hdd.service systemctl enable torrent-hdd-down.service systemctl enable torrent-hdd-pull.service +systemctl enable torrent-low.service +systemctl enable torrent-low-down.service +systemctl enable torrent-low-pull.service systemctl enable mount-hdd.service systemctl enable mount-smb.service diff --git a/config/examples/etc/systemd/services/media-server-down.service b/config/examples/etc/systemd/services/media-server-down.service index e660a7a..337c04b 100644 --- a/config/examples/etc/systemd/services/media-server-down.service +++ b/config/examples/etc/systemd/services/media-server-down.service @@ -1,7 +1,7 @@ [Unit] Description=Media server down Requires=docker.service -After=mount-hdd.service +After=mount-hdd.service mount-smb.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/torrent-low-down.service b/config/examples/etc/systemd/services/torrent-low-down.service new file mode 100644 index 0000000..3657898 --- /dev/null +++ b/config/examples/etc/systemd/services/torrent-low-down.service @@ -0,0 +1,14 @@ +[Unit] +Description=Torent client Service +Requires=docker.service +After=mount-hdd.service + +[Service] +Type=oneshot +RemainAfterExit=yes +WorkingDirectory=/home/dima/media +ExecStart=/usr/bin/docker-compose -f docker-compose-torrent-low.yml down +TimeoutStartSec=0 + +[Install] +WantedBy=default.target diff --git a/config/examples/etc/systemd/services/torrent-low-pull.service b/config/examples/etc/systemd/services/torrent-low-pull.service new file mode 100644 index 0000000..61ec872 --- /dev/null +++ b/config/examples/etc/systemd/services/torrent-low-pull.service @@ -0,0 +1,14 @@ +[Unit] +Description=Torrent update +Requires=docker.service +After=torrent-low-down.service + +[Service] +Type=oneshot +RemainAfterExit=yes +WorkingDirectory=/home/dima/media +ExecStart=/usr/bin/docker-compose -f docker-compose-torrent-low.yml pull +TimeoutStartSec=0 + +[Install] +WantedBy=default.target diff --git a/config/examples/etc/systemd/services/torrent-low.service b/config/examples/etc/systemd/services/torrent-low.service new file mode 100644 index 0000000..4ee0aa5 --- /dev/null +++ b/config/examples/etc/systemd/services/torrent-low.service @@ -0,0 +1,15 @@ +[Unit] +Description=Torrent start +Requires=docker.service +After=torrent-low-pull.service + +[Service] +Type=oneshot +RemainAfterExit=yes +WorkingDirectory=/home/dima/media +ExecStart=/usr/bin/docker-compose -f docker-compose-torrent-low.yml up +ExecStop=/usr/bin/docker-compose -f docker-compose-torrent-low.yml down +TimeoutStartSec=0 + +[Install] +WantedBy=default.target diff --git a/torrent/src/main/resources/scripts/run.sh b/torrent/src/main/resources/scripts/run.sh index 145b75d..b8b797c 100644 --- a/torrent/src/main/resources/scripts/run.sh +++ b/torrent/src/main/resources/scripts/run.sh @@ -1,21 +1,26 @@ #!/bin/bash -mkdir -p /home/app/transmission_config -if [ -e /home/app/transmission_config/.settings.lock ]; then - echo "The transmission service was already configured by this service" -else - cp /home/app/settings.json /home/app/transmission_config/settings.json - echo "The transmission service configured by this service" - echo "The transmission service configured by this service" > /home/app/transmission_config/.settings.lock -fi +TORRENT_IP_ARRAY=$(echo $TORRENT_IP | jq -r '.[]') -mkdir -p /home/app/transmission_config_hdd -if [ -e /home/app/transmission_config_hdd/.settings.lock ]; then - echo "The transmission hdd service was already configured by this service" -else - cp /home/app/settings.json /home/app/transmission_config_hdd/settings.json - echo "The transmission hdd service configured by this service" - echo "The transmission hdd service configured by this service" > /home/app/transmission_config_hdd/.settings.lock -fi +for ITEM in $TORRENT_IP_ARRAY +do + NAME=$(echo $ITEM | jq -r '.name // empty') + + if [ -n "$NAME" ]; then + CONFIG_PATH="/home/app/transmission_config_$NAME" + else + CONFIG_PATH="/home/app/transmission_config" + fi + + mkdir -p $CONFIG_PATH + + if [ -e $CONFIG_PATH/.settings.lock ]; then + echo "The transmission service was already configured by this service" + else + cp /home/app/settings.json $CONFIG_PATH/settings.json + echo "The transmission service configured by this service" + echo "The transmission service configured by this service" > $CONFIG_PATH/.settings.lock + fi +done java -Dlog4j.configuration=file:/home/app/log4j-${LOGS_LEVEL}.properties -jar /home/app/app.jar \ No newline at end of file