mirror of
https://gitlab.sectorq.eu/jaydee/python.git
synced 2025-12-14 10:44:52 +01:00
bitwarden
This commit is contained in:
@@ -9,12 +9,21 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
from wakeonlan import send_magic_packet
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
|
|
||||||
host = platform.node().lower()
|
host = platform.node().lower()
|
||||||
cmnd = "ps -ef|grep omv_backups.py|grep -v grep |grep -v {}|wc -l".format(pid)
|
cmnd = "ps -ef|grep omv_backups.py|grep -v grep |grep -v {}|wc -l".format(pid)
|
||||||
status, output = subprocess.getstatusoutput(cmnd)
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
|
|
||||||
|
def is_port_open(host, port):
|
||||||
|
try:
|
||||||
|
sock = socket.create_connection((host, port))
|
||||||
|
sock.close()
|
||||||
|
return True
|
||||||
|
except socket.error:
|
||||||
|
return False
|
||||||
|
|
||||||
print(output)
|
print(output)
|
||||||
if int(output) > 0:
|
if int(output) > 0:
|
||||||
print("Running already!")
|
print("Running already!")
|
||||||
@@ -83,17 +92,33 @@ if not host in backups:
|
|||||||
print(f"No backup jobs for {host}")
|
print(f"No backup jobs for {host}")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
print("Test connection")
|
print("Test connection")
|
||||||
try:
|
|
||||||
hm = socket.gethostbyaddr("omv.home.lan")
|
hm = socket.gethostbyaddr("omv.home.lan")
|
||||||
|
HOST_UP = os.system(f"ping -c 1 -w 2 omv.home.lan") == 0
|
||||||
|
print(HOST_UP)
|
||||||
|
if not HOST_UP:
|
||||||
|
print("Backup host down")
|
||||||
|
send_magic_packet('88:c9:b3:b5:23:d8')
|
||||||
|
|
||||||
|
hostdown = True
|
||||||
|
while hostdown:
|
||||||
HOST_UP = os.system(f"ping -c 1 -w 2 omv.home.lan") == 0
|
HOST_UP = os.system(f"ping -c 1 -w 2 omv.home.lan") == 0
|
||||||
print(HOST_UP)
|
|
||||||
if not HOST_UP:
|
if not HOST_UP:
|
||||||
print("Backup host down")
|
print("Backup host down, waiting")
|
||||||
sys.exit()
|
time.sleep(5)
|
||||||
except socket.herror:
|
else:
|
||||||
print("Unknown host")
|
print("host up")
|
||||||
|
hostdown = False
|
||||||
|
host = "omv.home.lan"
|
||||||
|
port = 22 # Replace with the port you want to test
|
||||||
|
if is_port_open(host, port):
|
||||||
|
print(f"Port {port} on {host} is open.")
|
||||||
|
else:
|
||||||
|
print(f"Port {port} on {host} is closed.")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for b in backups[host]:
|
for b in backups[host]:
|
||||||
topic = "sectorq/omv/backups/{}".format(b.lower())
|
topic = "sectorq/omv/backups/{}".format(b.lower())
|
||||||
if not backups[host][b]["active"]:
|
if not backups[host][b]["active"]:
|
||||||
|
|||||||
Reference in New Issue
Block a user