Added debug options to wrapper scripts to record output to logs/ dir (#8811)

* Ability to enable debug output with wrappers
Output is redirected to a per-device file in the log directory.

* Add warning

* Added some docs to help with debugging using this new option
This commit is contained in:
Tony Murray
2018-06-15 08:22:43 -05:00
committed by Neil Lathwood
parent 646a37f55e
commit fd77b23624
6 changed files with 60 additions and 26 deletions

View File

@@ -40,6 +40,7 @@ try:
import sys
import threading
import time
import argparse
except:
print "ERROR: missing one or more of the following python modules:"
@@ -85,6 +86,7 @@ except:
sys.exit(2)
service_path = config['install_dir'] + '/check-services.php'
log_dir = config['log_dir']
db_username = config['db_user']
db_password = config['db_pass']
@@ -192,13 +194,16 @@ service_devices = 0
Take the amount of threads we want to run in parallel from the commandline
if None are given or the argument was garbage, fall back to default of 16
"""
try:
amount_of_workers = int(sys.argv[1])
if amount_of_workers == 0:
print "ERROR: 0 threads is not a valid value"
sys.exit(2)
except:
amount_of_workers = 1
parser = argparse.ArgumentParser(description='Spawn multiple check-services.php processes in parallel.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-d', '--debug', action='store_true', default=False,
help="Enable debug output. WARNING: Leaving this enabled will consume a lot of disk space.")
parser.add_argument('workers', metavar='N', type=int, default=1, nargs='?',
help='The max number of workers allowed to run at one time. If too high this can overwelm your server.')
args = parser.parse_args()
amount_of_workers = args.workers
debug = args.debug
devices_list = []
@@ -302,8 +307,11 @@ def poll_worker():
# EOC5
try:
start_time = time.time()
command = "/usr/bin/env php %s -h %s >> /dev/null 2>&1" % (service_path, device_id)
output = "-d >> %s/services_device_%s.log" % (log_dir, device_id) if debug else ">> /dev/null"
command = "/usr/bin/env php %s -h %s %s 2>&1" % (service_path, device_id, output)
subprocess.check_call(command, shell=True)
elapsed_time = int(time.time() - start_time)
print_queue.put([threading.current_thread().name, device_id, elapsed_time])
except (KeyboardInterrupt, SystemExit):