Commit 934dfa9b authored by Alan Mitchell's avatar Alan Mitchell

Changed script to terminate old main_cron to use standard library packages.

Had trouble installing the 3rd party 'psutil' package on Webfaction servers.
parent ce0c5cf8
......@@ -5,9 +5,8 @@ time threshhold. Should be run with the django-extensions runscript facility:
This script is also called from the script.
import time
import getpass
import psutil
import subprocess
# Hold a main_cron process must be in seconds before being terminated.
OLD_SECS = 3600
......@@ -18,21 +17,12 @@ def run():
# determine the User name that is running BMON.
this_user = getpass.getuser()
# A list of all the old processes to terminate.
to_terminate = []
for p in psutil.process_iter(['username']):
if['username'] == this_user:
# Check all the pieces of the command (past the interpreter command in the first
# index) to see if the "main_cron" process is part of the name.
for fld in p.cmdline()[1:]:
if 'main_cron' in fld:
if time.time() - p.create_time() > OLD_SECS:
for p in to_terminate:
print(f"Terminating: {' '.join(p.cmdline())}")
_, alive = psutil.wait_procs(to_terminate, timeout=3)
for p in alive:
completed ='ps -u $USER -o pid,etimes,command', shell=True, text=True, check=False, stdout=subprocess.PIPE)
for proc in completed.stdout.splitlines():
if 'runscript main_cron' in proc:
flds = proc.split()
pid = flds[0].strip()
etime = float(flds[1])
if etime > OLD_SECS:
print(f'Terminating: {pid}')'kill {pid}', shell=True, check=False)
......@@ -22,4 +22,3 @@ xlrd==1.2.0
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment