From 7cab1bb7e8e048e1e3ef02ff448acd1781676368 Mon Sep 17 00:00:00 2001 From: ejparker Date: Mon, 2 Sep 2019 15:47:42 -0500 Subject: [PATCH] Eliminated video lxc, moved sonarr, radarr, lidarr, and jackett to single VM and moved rtorrent to separate VM. Switched windscribe back to openvpn. Still need to migrate ombi to separate VM. --- pillars/roles/lxc/video.sls | 28 +++++------ pillars/roles/mount/{video.sls => arr.sls} | 4 +- pillars/roles/mount/rtorrent.sls | 7 +++ pillars/roles/nginx/jackett.sls | 14 ++++++ pillars/roles/nginx/lidarr.sls | 14 ++++++ pillars/roles/nginx/ombi.sls | 14 ++++++ pillars/roles/nginx/radarr.sls | 14 ++++++ pillars/roles/nginx/rtorrent.sls | 14 ++++++ pillars/roles/nginx/sonarr.sls | 14 ++++++ pillars/servers/env/server/arr.sls | 1 + pillars/servers/roles/server/arr.sls | 12 +++++ pillars/servers/roles/server/ombi.sls | 2 +- pillars/servers/roles/server/rtorrent.sls | 6 +-- states/roles/maintain/jackett/init.sls | 6 +++ states/roles/maintain/lidarr/init.sls | 6 +++ states/roles/maintain/radarr/init.sls | 6 +++ states/roles/maintain/rtorrent/init.sls | 26 +++++----- states/roles/maintain/rtorrent/nginx.conf | 48 ++++++++----------- .../roles/maintain/rtorrent/rtorrent.service | 25 ++++------ states/roles/maintain/rtorrent/rtorrent.sh | 22 ++++++++- states/roles/maintain/rtorrent/rtorrent.timer | 11 +++++ states/roles/maintain/sonarr/init.sls | 6 +++ states/roles/maintain/windscribe/init.sls | 48 +++++++++---------- 23 files changed, 244 insertions(+), 104 deletions(-) rename pillars/roles/mount/{video.sls => arr.sls} (66%) create mode 100644 pillars/roles/mount/rtorrent.sls create mode 100644 pillars/roles/nginx/jackett.sls create mode 100644 pillars/roles/nginx/lidarr.sls create mode 100644 pillars/roles/nginx/ombi.sls create mode 100644 pillars/roles/nginx/radarr.sls create mode 100644 pillars/roles/nginx/rtorrent.sls create mode 100644 pillars/roles/nginx/sonarr.sls create mode 100644 pillars/servers/env/server/arr.sls create mode 100644 pillars/servers/roles/server/arr.sls create mode 100644 states/roles/maintain/rtorrent/rtorrent.timer diff --git a/pillars/roles/lxc/video.sls b/pillars/roles/lxc/video.sls index 9b02631..33ad090 100644 --- a/pillars/roles/lxc/video.sls +++ b/pillars/roles/lxc/video.sls @@ -1,19 +1,19 @@ lxc: - rtorrent: - bind_dirs: - - mnt/video - sonarr: - bind_dirs: - - mnt/video - radarr: - bind_dirs: - - mnt/video - lidarr: - bind_dirs: - - mnt/video +# rtorrent: +# bind_dirs: +# - mnt/video +# sonarr: +# bind_dirs: +# - mnt/video +# radarr: +# bind_dirs: +# - mnt/video +# lidarr: +# bind_dirs: +# - mnt/video # emby: # bind_dirs: # - mnt/video # - mnt/emby - ombi: [] - jackett: [] +# ombi: [] +# jackett: [] diff --git a/pillars/roles/mount/video.sls b/pillars/roles/mount/arr.sls similarity index 66% rename from pillars/roles/mount/video.sls rename to pillars/roles/mount/arr.sls index dc41109..018fa6c 100644 --- a/pillars/roles/mount/video.sls +++ b/pillars/roles/mount/arr.sls @@ -6,5 +6,5 @@ mount: directory: /mnt/butter/video user: mount ext4: - /mnt/lxc: - device: UUID=a11c4225-bf55-4888-ab15-589afde95510 + /mnt/data: + device: UUID=a11c4225-bf55-4888-ab15-589afde95510 \ No newline at end of file diff --git a/pillars/roles/mount/rtorrent.sls b/pillars/roles/mount/rtorrent.sls new file mode 100644 index 0000000..586869b --- /dev/null +++ b/pillars/roles/mount/rtorrent.sls @@ -0,0 +1,7 @@ +mount: + sshfs: + /mnt/video: + name: video + host: host.actcur.com + directory: /mnt/butter/video + user: mount \ No newline at end of file diff --git a/pillars/roles/nginx/jackett.sls b/pillars/roles/nginx/jackett.sls new file mode 100644 index 0000000..46aa9d8 --- /dev/null +++ b/pillars/roles/nginx/jackett.sls @@ -0,0 +1,14 @@ +nginx: + jackett: + auth: 2fa + default: no + https: + port: 9117 + prot: http + +portal: + Media: + jackett: + name: Torrent Indexers + summary: Jackett Server + public: false diff --git a/pillars/roles/nginx/lidarr.sls b/pillars/roles/nginx/lidarr.sls new file mode 100644 index 0000000..10d88ca --- /dev/null +++ b/pillars/roles/nginx/lidarr.sls @@ -0,0 +1,14 @@ +nginx: + lidarr: + auth: 2fa + default: no + https: + port: 8686 + prot: http + +portal: + Media: + lidarr: + name: Music Downloader + summary: Music Server + public: false diff --git a/pillars/roles/nginx/ombi.sls b/pillars/roles/nginx/ombi.sls new file mode 100644 index 0000000..27b6b8c --- /dev/null +++ b/pillars/roles/nginx/ombi.sls @@ -0,0 +1,14 @@ +nginx: + ombi: + auth: none + default: no + https: + port: 5000 + prot: http + +portal: + Media: + ombi: + name: TV/Movie Requests + summary: OMBI Plex Requests Server + public: true \ No newline at end of file diff --git a/pillars/roles/nginx/radarr.sls b/pillars/roles/nginx/radarr.sls new file mode 100644 index 0000000..5f44bf0 --- /dev/null +++ b/pillars/roles/nginx/radarr.sls @@ -0,0 +1,14 @@ +nginx: + radarr: + auth: 2fa + default: no + https: + port: 7878 + prot: http + +portal: + Media: + radarr: + name: Movie Downloader + summary: Radarr Server + public: false diff --git a/pillars/roles/nginx/rtorrent.sls b/pillars/roles/nginx/rtorrent.sls new file mode 100644 index 0000000..5696f16 --- /dev/null +++ b/pillars/roles/nginx/rtorrent.sls @@ -0,0 +1,14 @@ +nginx: + rtorrent: + auth: 2fa + default: no + https: + port: 5080 + prot: http + +portal: + Media: + rtorrent: + name: Torrents + summary: Rtorrent Torrent Server + public: false \ No newline at end of file diff --git a/pillars/roles/nginx/sonarr.sls b/pillars/roles/nginx/sonarr.sls new file mode 100644 index 0000000..8700413 --- /dev/null +++ b/pillars/roles/nginx/sonarr.sls @@ -0,0 +1,14 @@ +nginx: + sonarr: + auth: 2fa + default: no + https: + port: 8989 + prot: http + +portal: + Media: + sonarr: + name: TV Show Downloader + summary: Sonarr Server + public: false \ No newline at end of file diff --git a/pillars/servers/env/server/arr.sls b/pillars/servers/env/server/arr.sls new file mode 100644 index 0000000..2fdef9a --- /dev/null +++ b/pillars/servers/env/server/arr.sls @@ -0,0 +1 @@ +env: prod diff --git a/pillars/servers/roles/server/arr.sls b/pillars/servers/roles/server/arr.sls new file mode 100644 index 0000000..56d06ba --- /dev/null +++ b/pillars/servers/roles/server/arr.sls @@ -0,0 +1,12 @@ +grains: + roles: + - server + - nrpe + - saltminion + - nginx-proxy + - arr + - sonarr + - radarr + - lidarr + - jackett + - ytdownloader diff --git a/pillars/servers/roles/server/ombi.sls b/pillars/servers/roles/server/ombi.sls index 81a3195..19bc3de 100644 --- a/pillars/servers/roles/server/ombi.sls +++ b/pillars/servers/roles/server/ombi.sls @@ -3,5 +3,5 @@ grains: - server - nrpe - saltminion - - lxc_container + - nginx-proxy - ombi diff --git a/pillars/servers/roles/server/rtorrent.sls b/pillars/servers/roles/server/rtorrent.sls index d38481c..46cc181 100644 --- a/pillars/servers/roles/server/rtorrent.sls +++ b/pillars/servers/roles/server/rtorrent.sls @@ -3,6 +3,6 @@ grains: - server - nrpe - saltminion - - lxc_container - - rtorrent - - windscribe \ No newline at end of file + - nginx-proxy + - windscribe + - rtorrent \ No newline at end of file diff --git a/states/roles/maintain/jackett/init.sls b/states/roles/maintain/jackett/init.sls index 8f682e6..dcb7ef7 100644 --- a/states/roles/maintain/jackett/init.sls +++ b/states/roles/maintain/jackett/init.sls @@ -1,3 +1,9 @@ +/var/lib/jackett: + file.symlink: + - target: /mnt/data/jackett + - force: true + - mkdirs: true + #package is in aur repo jackett: pkg.installed diff --git a/states/roles/maintain/lidarr/init.sls b/states/roles/maintain/lidarr/init.sls index 9688664..bef646c 100644 --- a/states/roles/maintain/lidarr/init.sls +++ b/states/roles/maintain/lidarr/init.sls @@ -1,3 +1,9 @@ +/var/lib/lidarr: + file.symlink: + - target: /mnt/data/lidarr + - force: true + - mkdirs: true + #package is in aur repo lidarr: pkg.installed diff --git a/states/roles/maintain/radarr/init.sls b/states/roles/maintain/radarr/init.sls index cbfc8c1..f4cba27 100644 --- a/states/roles/maintain/radarr/init.sls +++ b/states/roles/maintain/radarr/init.sls @@ -1,3 +1,9 @@ +/var/lib/radarr: + file.symlink: + - target: /mnt/data/radarr + - force: true + - mkdirs: true + #package is in aur repo radarr: pkg.installed diff --git a/states/roles/maintain/rtorrent/init.sls b/states/roles/maintain/rtorrent/init.sls index ee5fad1..9e45d6d 100644 --- a/states/roles/maintain/rtorrent/init.sls +++ b/states/roles/maintain/rtorrent/init.sls @@ -2,14 +2,6 @@ rtorrent: pkg.installed rutorrent: pkg.installed -rtorrent_nginx: - pkg.installed: - - name: nginx - service.running: - - name: nginx - - enable: true - - watch: - - file: /etc/nginx/nginx.conf rtorrent-screen: pkg.installed: - name: screen @@ -34,7 +26,7 @@ rtorrent-php-fpm: - watch: - file: /etc/php/php.ini -/etc/nginx/nginx.conf: +/etc/nginx/conf.d/rtorrent-backend.conf: file.managed: - source: salt://roles/maintain/rtorrent/nginx.conf - user: root @@ -78,9 +70,15 @@ rtorrent-php-fpm: - group: root - mode: 644 - mkdirs: true -rtorrent_service: + +/etc/systemd/system/rtorrent.timer: + file.managed: + - source: salt://roles/maintain/rtorrent/rtorrent.timer + - user: root + - group: root + - mode: 644 + - mkdirs: true +rtorrent_timer: service.running: - - name: rtorrent - - enable: false - - watch: - - file: /root/.rtorrent.rc \ No newline at end of file + - name: rtorrent.timer + - enable: true \ No newline at end of file diff --git a/states/roles/maintain/rtorrent/nginx.conf b/states/roles/maintain/rtorrent/nginx.conf index 2c7e5f3..adc2a06 100644 --- a/states/roles/maintain/rtorrent/nginx.conf +++ b/states/roles/maintain/rtorrent/nginx.conf @@ -1,31 +1,21 @@ -worker_processes 1; -events { - worker_connections 1024; -} -http { - include mime.types; - default_type application/octet-stream; - sendfile on; - keepalive_timeout 65; - server { - listen 5080; - server_name localhost; - root /usr/share/webapps/rutorrent; - location / { - index index.html index.htm; - } - location ~ \.php$ { - fastcgi_pass unix:/run/php-fpm/php-fpm.sock; - fastcgi_index index.php; - include fastcgi.conf; - } - location /RPC2 { - include scgi_params; - scgi_pass localhost:5050; - } - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } +server { + listen 5080; + server_name localhost; + root /usr/share/webapps/rutorrent; + location / { + index index.html index.htm; + } + location ~ \.php$ { + fastcgi_pass unix:/run/php-fpm/php-fpm.sock; + fastcgi_index index.php; + include fastcgi.conf; + } + location /RPC2 { + include scgi_params; + scgi_pass localhost:5050; + } + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; } } diff --git a/states/roles/maintain/rtorrent/rtorrent.service b/states/roles/maintain/rtorrent/rtorrent.service index e9198d9..43043c8 100644 --- a/states/roles/maintain/rtorrent/rtorrent.service +++ b/states/roles/maintain/rtorrent/rtorrent.service @@ -1,18 +1,11 @@ - [Unit] - Description=rTorrent - After=network.target - After=openvpn-client@windscribe-denmark +[Unit] +Description=rTorrent - [Service] - User=root - Type=notify - KillMode=none - ExecStartPre=/usr/bin/bash -c 'if test -e /mnt/video/rtorrent/.session/rtorrent.lock && test -z `pidof rtorrent`; then rm -f /mnt/video/rtorrent/.session/rtorrent.lock; fi' - ExecStart=/bin/bash -c 'sleep 10;/usr/bin/screen -dmfa -S rtorrent /usr/bin/rtorrent -b `ifconfig tun0 | grep "inet " | grep -Po "(?<=inet).*(?=net)"`' - ExecStop=/usr/bin/bash -c "test `pidof rtorrent` && killall -w -s 2 /usr/bin/rtorrent" - WorkingDirectory=/mnt/video/rtorrent - WatchdogSec=420 - Restart=always +[Service] +User=root +Type=simple +KillMode=none +ExecStart=/bin/bash /opt/scripts/rtorrent.sh - [Install] - WantedBy=default.target \ No newline at end of file +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/states/roles/maintain/rtorrent/rtorrent.sh b/states/roles/maintain/rtorrent/rtorrent.sh index ba0c220..07cf3b2 100644 --- a/states/roles/maintain/rtorrent/rtorrent.sh +++ b/states/roles/maintain/rtorrent/rtorrent.sh @@ -1,2 +1,22 @@ #!/bin/bash -/usr/bin/screen -dmfa -S rtorrent /usr/bin/rtorrent -b /usr/bin/screen -dmfa -S rtorrent /usr/bin/rtorrent -b `ifconfig tun0 | grep "inet " | grep -Po "(?<=inet).*(?=net)"` +#resurrect rtorrent when it dies and restart every 6 hours +hour=`date | grep -Po "\d\d:\d\d:\d\d" | grep -Po "^\d\d:\d\d"` + +if [ "$hour" = "00:00" ] || [ "$hour" = "06:00" ] || [ "$hour" = "12:00" ] || [ "$hour" = "18:00" ];then + killall -w -s 2 /usr/bin/rtorrent + systemctl restart openvpn-client@windscribe-denmark.service +fi + +currentip=`ps aux | grep rtorrent | grep -v "SCREEN" | grep -Po "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"` +tunip=`ip addr show tun0 | grep -Po "inet \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" | grep -Po "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"` + +if [ "$currentip" = "$tunip" ];then + echo "rtorrent is up" +else + echo "restarting rtorrent" + killall -w -s 2 /usr/bin/rtorrent + rm -f /mnt/video/rtorrent/.session/rtorrent.lock + sleep 5;/usr/bin/screen -dmfa -S rtorrent /usr/bin/rtorrent -b $tunip +fi + + diff --git a/states/roles/maintain/rtorrent/rtorrent.timer b/states/roles/maintain/rtorrent/rtorrent.timer new file mode 100644 index 0000000..09eb047 --- /dev/null +++ b/states/roles/maintain/rtorrent/rtorrent.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Verify that rtorrent is running + +[Timer] +OnBootSec=2min +OnUnitActiveSec=1min + +Unit=rtorrent.service + +[Install] +WantedBy=timers.target diff --git a/states/roles/maintain/sonarr/init.sls b/states/roles/maintain/sonarr/init.sls index cd83510..2bc9fe4 100644 --- a/states/roles/maintain/sonarr/init.sls +++ b/states/roles/maintain/sonarr/init.sls @@ -1,3 +1,9 @@ +/var/lib/sonarr: + file.symlink: + - target: /mnt/data/sonarr + - force: true + - mkdirs: true + #package is in aur repo sonarr: pkg.installed diff --git a/states/roles/maintain/windscribe/init.sls b/states/roles/maintain/windscribe/init.sls index bf5dee2..3fb1e31 100644 --- a/states/roles/maintain/windscribe/init.sls +++ b/states/roles/maintain/windscribe/init.sls @@ -1,10 +1,10 @@ -windscribe: - service.running: - - enable: true +#windscribe: +# service.running: +# - enable: true -#windscribe-vpn-pkg: -# pkg.installed: -# - name: openvpn +windscribe-vpn-pkg: + pkg.installed: + - name: openvpn #/etc/firewalld/direct.xml: # file.managed: @@ -13,26 +13,26 @@ windscribe: # - group: root # - mode: 644 -#/etc/openvpn/client/windscribe-denmark.conf: -# file.managed: -# - source: salt://roles/maintain/windscribe/windscribe-denmark.conf -# - user: root -# - group: root -# - mode: 644 +/etc/openvpn/client/windscribe-denmark.conf: + file.managed: + - source: salt://roles/maintain/windscribe/windscribe-denmark.conf + - user: root + - group: root + - mode: 644 -#/etc/openvpn/client/windscribe.login: -# file.managed: -# - source: salt://secure/files/windscribe.login -# - user: root -# - group: root -# - mode: 600 +/etc/openvpn/client/windscribe.login: + file.managed: + - source: salt://secure/files/windscribe.login + - user: root + - group: root + - mode: 600 -#openvpn-client@windscribe-denmark: -# service.running: -# - enable: true -# - watch: -# - file: /etc/openvpn/client/windscribe-denmark.conf -# - file: /etc/openvpn/client/windscribe.login +openvpn-client@windscribe-denmark: + service.running: + - enable: true + - watch: + - file: /etc/openvpn/client/windscribe-denmark.conf + - file: /etc/openvpn/client/windscribe.login #windscribe-firewall: # service.running: