test candidate for full operation

This commit is contained in:
2025-08-24 21:57:15 -07:00
parent cc24088bbe
commit 0a5a7cc32c
9 changed files with 113 additions and 107 deletions

View File

@ -13,16 +13,13 @@ def start_service():
try:
# Run the command using subprocess.run()
process = subprocess.Popen(command, shell=True)
except subprocess.CalledProcessError as e:
return {"Error": e.strip('\n')}
command = "systemctl status {{ service_control_name }} | grep Active | cut -d ':' -f 2- | cut -b 2-"
try:
# Run the command using subprocess.run()
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
return {"Message": result.stdout.strip('\n')}
except subprocess.CalledProcessError as e:
return {"Error": e.strip('\n')}
@ -31,7 +28,6 @@ def stop_service():
try:
# Run the command using subprocess.run()
process = subprocess.Popen(command, shell=True)
except subprocess.CalledProcessError as e:
return {"Error": e.strip('\n')}
@ -52,7 +48,6 @@ def service_status():
status = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
if status.stdout.strip('\n') == "active":
elapsed_time = check_time_elapsed(result.stdout.strip('\n'))
times_up(elapsed_time)
else:
elapsed_time = -1
return {"Elapsed_Time": elapsed_time, "Service Name": "{{ service_control_name }}", "Message": result.stdout.strip('\n'), "Status": status.stdout.strip('\n')}
@ -71,7 +66,6 @@ def save_duration(new_duration):
seconds = 7200
if new_duration == "3":
seconds = 21600
info = {
"duration": new_duration,
"seconds": seconds
@ -91,40 +85,18 @@ def get_duration():
def check_time_elapsed(time_str):
# Extract the time part from the string
datetime_extract = time_str.split("since ")[1].split(";")[0]
try:
time_format = "%a %Y-%m-%d %H:%M:%S %Z"
given_time = datetime.strptime(datetime_extract, time_format)
except ValueError as e:
raise ValueError(f"Error parsing the time string: {datetime_extract}" + str(e))
# Get the current time
now = datetime.now()
# Calculate the difference in seconds
delta = now - given_time
total_seconds = int(delta.total_seconds())
return total_seconds
def times_up(time_elapsed):
duration_json = get_duration()
stored_duration = duration_json["duration"]
if stored_duration == 0:
if time_elapsed > 1800:
stop_service()
elif stored_duration == 1:
if time_elapsed > 3600:
stop_service()
elif stored_duration == 2:
if time_elapsed > 7200:
stop_service()
elif stored_duration == 3:
if time_elapsed > 21600:
stop_service()
@app.route('/start', methods=['GET'])
def start():
try: