From d98a22abffd7270dd4437822ceb8b78a75d83f75 Mon Sep 17 00:00:00 2001 From: YuruC3 <98943911+YuruC3@users.noreply.github.com> Date: Fri, 15 Dec 2023 20:05:44 +0100 Subject: [PATCH] Add files via upload --- NPM-TEST/KPAVD-VM-1.conf | 58 +++++++++++++++++++++++++++ NPM-TEST/KPAVD-VM-2.conf | 58 +++++++++++++++++++++++++++ NPM-TEST/KPAVD-VM-3.conf | 58 +++++++++++++++++++++++++++ NPM-TEST/KPAVD-VM-LOAD-BALANCING.conf | 24 +++++++++++ NPM-TEST/check_docker_container.sh | 22 ++++++++++ NPM-TEST/rsync_between_nodes.sh | 57 ++++++++++++++++++++++++++ 6 files changed, 277 insertions(+) create mode 100644 NPM-TEST/KPAVD-VM-1.conf create mode 100644 NPM-TEST/KPAVD-VM-2.conf create mode 100644 NPM-TEST/KPAVD-VM-3.conf create mode 100644 NPM-TEST/KPAVD-VM-LOAD-BALANCING.conf create mode 100644 NPM-TEST/check_docker_container.sh create mode 100644 NPM-TEST/rsync_between_nodes.sh diff --git a/NPM-TEST/KPAVD-VM-1.conf b/NPM-TEST/KPAVD-VM-1.conf new file mode 100644 index 0000000..ff978b0 --- /dev/null +++ b/NPM-TEST/KPAVD-VM-1.conf @@ -0,0 +1,58 @@ +vrrp_script track_npm { + script "/etc/keepalived/check_docker_container.sh yuru_app_1" + interval 5 + fall 1 + rise 30 +} + +vrrp_instance TEST-NPM-V1 { + state MASTER + interface eth0 + virtual_router_id 40 + priority 100 + advert_int 1 + + unicast_src_ip 192.168.1.130 + unicast_peer { + 192.168.1.131 + 192.168.1.132 + } + + authentication { + auth_type PASS + auth_pass Loli6969 + } + + virtual_ipaddress { + 192.168.1.125/24 + } + + track_script { + track_npm + } + +} + +virtual_server 192.168.1.125 80 { + delay_loop 6 + lb_algo rr + lb_kind NAT + protocol TCP + + real_server 192.168.1.130 80 { + TCP_CHECK { + connect_timeout 10 + } + } + real_server 192.168.1.131 80 { + TCP_CHECK { + connect_timeout 10 + } + } + real_server 192.168.1.132 80 { + TCP_CHECK { + connect_timeout 10 + } + } + +} diff --git a/NPM-TEST/KPAVD-VM-2.conf b/NPM-TEST/KPAVD-VM-2.conf new file mode 100644 index 0000000..26ad694 --- /dev/null +++ b/NPM-TEST/KPAVD-VM-2.conf @@ -0,0 +1,58 @@ +vrrp_script track_npm { + script "/etc/keepalived/check_docker_container.sh npm" + interval 5 + fall 1 + rise 30 +} + +vrrp_instance TEST-NPM-V1 { + state BACKUP + interface eth0 + virtual_router_id 40 + priority 10 + advert_int 1 + + unicast_src_ip 192.168.1.131 + unicast_peer { + 192.168.1.130 + 192.168.1.132 + } + + authentication { + auth_type PASS + auth_pass Loli6969 + } + + virtual_ipaddress { + 192.168.1.125/24 + } + + track_script { + track_npm + } + +} + +virtual_server 192.168.1.125 80 { + delay_loop 6 + lb_algo rr + lb_kind NAT + protocol TCP + + real_server 192.168.1.130 80 { + TCP_CHECK { + connect_timeout 10 + } + } + real_server 192.168.1.131 80 { + TCP_CHECK { + connect_timeout 10 + } + } + real_server 192.168.1.132 80 { + TCP_CHECK { + connect_timeout 10 + } + } + +} diff --git a/NPM-TEST/KPAVD-VM-3.conf b/NPM-TEST/KPAVD-VM-3.conf new file mode 100644 index 0000000..1683ea9 --- /dev/null +++ b/NPM-TEST/KPAVD-VM-3.conf @@ -0,0 +1,58 @@ +vrrp_script track_npm { + script "/etc/keepalived/check_docker_container.sh npm" + interval 5 + fall 1 + rise 30 +} + +vrrp_instance TEST-NPM-V1 { + state BACKUP + interface eth0 + virtual_router_id 40 + priority 11 + advert_int 1 + + unicast_src_ip 192.168.1.132 + unicast_peer { + 192.168.1.130 + 192.168.1.131 + } + + authentication { + auth_type PASS + auth_pass Loli6969 + } + + virtual_ipaddress { + 192.168.1.125/24 + } + + track_script { + track_npm + } + +} + +virtual_server 192.168.1.125 80 { + delay_loop 6 + lb_algo rr + lb_kind NAT + protocol TCP + + real_server 192.168.1.130 80 { + TCP_CHECK { + connect_timeout 10 + } + } + real_server 192.168.1.131 80 { + TCP_CHECK { + connect_timeout 10 + } + } + real_server 192.168.1.132 80 { + TCP_CHECK { + connect_timeout 10 + } + } + +} diff --git a/NPM-TEST/KPAVD-VM-LOAD-BALANCING.conf b/NPM-TEST/KPAVD-VM-LOAD-BALANCING.conf new file mode 100644 index 0000000..b3b710e --- /dev/null +++ b/NPM-TEST/KPAVD-VM-LOAD-BALANCING.conf @@ -0,0 +1,24 @@ + +virtual_server 192.168.1.125 443 { + delay_loop 6 + lb_algo rr + lb_kind NAT + protocol TCP + + real_server 192.168.1.130 443 { + TCP_CHECK { + connect_timeout 10 + } + } + real_server 192.168.1.131 443 { + TCP_CHECK { + connect_timeout 10 + } + } + real_server 192.168.1.132 443 { + TCP_CHECK { + connect_timeout 10 + } + } + +} diff --git a/NPM-TEST/check_docker_container.sh b/NPM-TEST/check_docker_container.sh new file mode 100644 index 0000000..4153cf2 --- /dev/null +++ b/NPM-TEST/check_docker_container.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +container_name=$1 + +# Debugging output +echo "Checking container: $container_name" + +state_restarting=$(sudo docker inspect --format="{{.State.Restarting}}" "$container_name") +state_running=$(sudo docker inspect --format="{{.State.Running}}" "$container_name" 2> /dev/null) + +# Debugging output +echo "Restarting: $state_restarting" +echo "Running: $state_running" + +if [ "$state_restarting" = "false" ] && [ "$state_running" = "true" ]; then + echo "Container is in the expected state. Exiting with status 0." + exit 0 +else + echo "Container is not in the expected state. Exiting with status 1." + exit 1 +fi + diff --git a/NPM-TEST/rsync_between_nodes.sh b/NPM-TEST/rsync_between_nodes.sh new file mode 100644 index 0000000..ea6c705 --- /dev/null +++ b/NPM-TEST/rsync_between_nodes.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# CHECK IF ALL ARGUMENTS HAVE BEEN PASSED +if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then + + echo "You need to pass three arguments." + echo "frst argument == container name" + echo "scnd argument == local_username" + echo "thrd argument == remote_username" + + exit + +fi + +# RSYNC FUNCTION +rsync_npmz () { + # $1 == local_username input + # $2 == remote_username input + + # NODE-2 + rsync -avru /home/$1/npm/ $2@192.168.25.15:/home/$2/npm/ + + # NODE-3 + rsync -avru /home/$1/npm/ $2@192.168.25.17:/home/$2/npm/ + +} + +# DEF VARIABLE NAMES +container_name=$1 + +local_username=$2 + +remote_username=$3 + +state_restarting=$(sudo docker inspect --format="{{.State.Restarting}}" "$container_name") +state_running=$(sudo docker inspect --format="{{.State.Running}}" "$container_name" 2> /dev/null) + +# MAIN CODE +if [ "$state_restarting" = "false" ] && [ "$state_running" = "true" ]; then + + echo "Container is up, that's goood." + + sleep 30; + + rsync_npmz $local_username $remote_username + +else + echo "Container is down, tho it should not be." + + rsync_npmz $local_username $remote_username +fi + +# AFTER RSYNCING +sudo docker-compose -f "/home/$local_username/npm/docker-compose.yml" up + +echo "NPM has been started." +echo "Bye"