Compare commits
3 Commits
8660793ec2
...
521d08969b
| Author | SHA1 | Date | |
|---|---|---|---|
| 521d08969b | |||
| 74ba296cda | |||
| a5fb874a20 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
venv
|
venv
|
||||||
|
docker-compose.dev.yaml
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
FROM python:3.14.7-alpine3.24
|
FROM python:3.14.7-alpine3.24
|
||||||
|
|
||||||
|
RUN apk update && \
|
||||||
|
apk add ipmitool
|
||||||
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
PYTHONUNBUFFERED=1
|
PYTHONUNBUFFERED=1
|
||||||
|
|||||||
32
main.py
32
main.py
@@ -32,6 +32,7 @@ AUTO_ADD_NAME: Final[str] = os.getenv("AUTO_ADD_NAME", "autoBackupScript_one-sho
|
|||||||
|
|
||||||
RUN_SCHEDULE: Final[str] = os.getenv("RUN_SCHEDULE", "45 17 * * 5")
|
RUN_SCHEDULE: Final[str] = os.getenv("RUN_SCHEDULE", "45 17 * * 5")
|
||||||
RUN_SCHEDULE_TZ: Final[str] = os.getenv("RUN_SCHEDULE_TZ", "Europe/Stockholm")
|
RUN_SCHEDULE_TZ: Final[str] = os.getenv("RUN_SCHEDULE_TZ", "Europe/Stockholm")
|
||||||
|
RUN_ONE_SHOT: Final[bool] = bool(os.getenv("RUN_ONE_SHOT", False))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -160,21 +161,21 @@ def theCodeBasically():
|
|||||||
# print(epoch_time)
|
# print(epoch_time)
|
||||||
|
|
||||||
# Check if power is on
|
# Check if power is on
|
||||||
PWR_STATE = subprocess.run(["ipmitool", "-I", "lanplus","-H", IDRAC,"-U", IDRAC_USR,"-P", IDRAC_PWD,"chassis", "power", "status",],capture_output=True,text=True,)
|
PWR_STATE = subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus","-H", IDRAC,"-U", IDRAC_USR,"-P", IDRAC_PWD,"chassis", "power", "status",],capture_output=True,text=True,)
|
||||||
|
|
||||||
if PWR_STATE.returncode != 0:
|
if PWR_STATE.returncode != 0:
|
||||||
raise RuntimeError(f"ipmitool failed: {PWR_STATE.stderr.strip()}")
|
raise RuntimeError(f"/usr/sbin/ipmitool failed: {PWR_STATE.stderr.strip()}")
|
||||||
|
|
||||||
if "off" in PWR_STATE.stdout.lower():
|
if "off" in PWR_STATE.stdout.lower():
|
||||||
subprocess.run(["ipmitool", "-I", "lanplus","-H", IDRAC,"-U", IDRAC_USR,"-P", IDRAC_PWD,"chassis", "power", "on",],check=True,)
|
subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus","-H", IDRAC,"-U", IDRAC_USR,"-P", IDRAC_PWD,"chassis", "power", "on",],check=True,)
|
||||||
|
|
||||||
|
|
||||||
# PWR_STATE = subprocess.run(["ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "status"], capture_output=True)
|
# PWR_STATE = subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "status"], capture_output=True)
|
||||||
|
|
||||||
# try:
|
# try:
|
||||||
# # power on if needed
|
# # power on if needed
|
||||||
# if "off" in str(PWR_STATE.stdout.decode()[-4:]):
|
# if "off" in str(PWR_STATE.stdout.decode()[-4:]):
|
||||||
# subprocess.run(["ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "on"]) # , capture_output=True
|
# subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "on"]) # , capture_output=True
|
||||||
# except Exception as e:
|
# except Exception as e:
|
||||||
# print("Most likely wrong password, username or hostname has been passed for idrac.\nExiting\n")
|
# print("Most likely wrong password, username or hostname has been passed for idrac.\nExiting\n")
|
||||||
# sys.exit(1)
|
# sys.exit(1)
|
||||||
@@ -345,6 +346,10 @@ def theCodeBasically():
|
|||||||
|
|
||||||
|
|
||||||
(stdin, stdout, stderr) = ssh.exec_command(f"proxmox-backup-manager sync-job run {AUTO_ADD_NAME}")
|
(stdin, stdout, stderr) = ssh.exec_command(f"proxmox-backup-manager sync-job run {AUTO_ADD_NAME}")
|
||||||
|
|
||||||
|
# (stdin, stdout, stderr) = ssh.exec_command(
|
||||||
|
# f"nohup proxmox-backup-manager sync-job run {AUTO_ADD_NAME} >/var/log/{AUTO_ADD_NAME}.log 2>&1 </dev/null &"
|
||||||
|
# )
|
||||||
# ssh.exec_command(f"proxmox-backup-manager sync-job run {AUTO_ADD_NAME}")
|
# ssh.exec_command(f"proxmox-backup-manager sync-job run {AUTO_ADD_NAME}")
|
||||||
# print("here it runs the sync-job")
|
# print("here it runs the sync-job")
|
||||||
# print(stdout.read().decode())
|
# print(stdout.read().decode())
|
||||||
@@ -354,6 +359,9 @@ def theCodeBasically():
|
|||||||
|
|
||||||
if syncJobRunExitCode != 0:
|
if syncJobRunExitCode != 0:
|
||||||
raise RuntimeError(f"Sync job failed: {stderr.read().decode()}")
|
raise RuntimeError(f"Sync job failed: {stderr.read().decode()}")
|
||||||
|
# raise RuntimeError(f"Failed to start sync job: {stderr.read().decode()}")
|
||||||
|
else:
|
||||||
|
print("Sync successful")
|
||||||
|
|
||||||
# Give some time for PBS to "start" the sync-job task
|
# Give some time for PBS to "start" the sync-job task
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
@@ -377,6 +385,11 @@ def theCodeBasically():
|
|||||||
while currenttasks:
|
while currenttasks:
|
||||||
|
|
||||||
print("Waiting 1 minute before checking tasks again")
|
print("Waiting 1 minute before checking tasks again")
|
||||||
|
|
||||||
|
print("Remaining jobs:")
|
||||||
|
for job in currenttasks:
|
||||||
|
print(f"Task {job} Amount {currenttasks[job]}")
|
||||||
|
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
|
|
||||||
currenttasks = getCurrentTasks(ssh, limitOfTasks=PBS_TASK_LIMIT)
|
currenttasks = getCurrentTasks(ssh, limitOfTasks=PBS_TASK_LIMIT)
|
||||||
@@ -384,6 +397,7 @@ def theCodeBasically():
|
|||||||
|
|
||||||
if time.monotonic() - SYNC_JOB_DATE >= (PBS_MAX_RUNTIME_MIN * 60):
|
if time.monotonic() - SYNC_JOB_DATE >= (PBS_MAX_RUNTIME_MIN * 60):
|
||||||
# print(SYNC_JOB_DATE - time.monotonic())
|
# print(SYNC_JOB_DATE - time.monotonic())
|
||||||
|
|
||||||
# Forcefully skip if these tasks are running. reader task is, I think, PVE backup
|
# Forcefully skip if these tasks are running. reader task is, I think, PVE backup
|
||||||
# Also otherjob is something else and it is better to wait if there is one otherjob
|
# Also otherjob is something else and it is better to wait if there is one otherjob
|
||||||
if (
|
if (
|
||||||
@@ -412,15 +426,17 @@ def theCodeBasically():
|
|||||||
print("PBS is powered off")
|
print("PBS is powered off")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
subprocess.run(["ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "off"])
|
subprocess.run(["/usr/sbin/ipmitool", "-I", "lanplus", "-H", IDRAC, "-U", IDRAC_USR, "-P", IDRAC_PWD, "chassis", "power", "off"])
|
||||||
|
|
||||||
# sys.exit(0)
|
# sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
if RUN_ONE_SHOT:
|
||||||
|
theCodeBasically()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
scheduler = BlockingScheduler(timezone=RUN_SCHEDULE_TZ)
|
||||||
scheduler = BlockingScheduler()
|
|
||||||
scheduler.add_job(
|
scheduler.add_job(
|
||||||
theCodeBasically,
|
theCodeBasically,
|
||||||
CronTrigger.from_crontab(
|
CronTrigger.from_crontab(
|
||||||
|
|||||||
Reference in New Issue
Block a user