use os.popopen manually

This commit is contained in:
Karol Wypchlo 2020-10-06 12:12:19 +02:00
parent 9b6d61aa7e
commit 1922c4cd98
1 changed files with 5 additions and 6 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import asyncio, json, os, re, sys, traceback, discord, requests, subprocess import asyncio, json, os, re, sys, traceback, discord, requests, time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from bot_utils import setup, send_msg from bot_utils import setup, send_msg
@ -98,14 +98,13 @@ async def check_disk():
# and shut down sia container so it doesn't get corrupted # and shut down sia container so it doesn't get corrupted
if int(volumes[vol]) < FREE_DISK_SPACE_THRESHOLD_CRITICAL: if int(volumes[vol]) < FREE_DISK_SPACE_THRESHOLD_CRITICAL:
free_space_gb = "{:.2f}".format(int(volumes[vol]) / GB) free_space_gb = "{:.2f}".format(int(volumes[vol]) / GB)
message = "CRITICAL! Very low disk space: {}GiB".format(free_space_gb) message = "CRITICAL! Very low disk space: {}GiB, **siad stopped**!".format(free_space_gb)
inspect = os.popen("docker inspect sia").read().strip() inspect = os.popen("docker inspect sia").read().strip()
inspect_json = json.loads(inspect) inspect_json = json.loads(inspect)
if inspect_json[0]["State"]["Running"] == True: if inspect_json[0]["State"]["Running"] == True:
message += ", **stopping siad container**!" os.popen("docker exec health-check cli/disable") # mark portal as unhealthy
subprocess.Popen('/home/user/skynet-webportal/scripts/portal-down.sh') time.sleep(300) # wait 5 minutes to propagate dns changes
else: os.popen("docker stop sia") # stop sia container
message += ", siad container is already stopped!"
return await send_msg(client, message, force_notify=True) return await send_msg(client, message, force_notify=True)
# if we're reached a free disk space threshold we need to send proper notice # if we're reached a free disk space threshold we need to send proper notice