| 628 | logger.info("Performing command: %s" % command) |
| 629 | |
| 630 | def executeCommand(command, logger): |
| 631 | time.sleep(0.5) #add a small delay to make sure the response is sent |
| 632 | try: |
| 633 | p = sarge.run(command, stderr=sarge.Capture()) |
| 634 | if p.returncode != 0: |
| 635 | returncode = p.returncode |
| 636 | stderr_text = p.stderr.text |
| 637 | logger.warn("Command failed with return code %i: %s" % (returncode, stderr_text)) |
| 638 | sendResponse({'success': False}) |
| 639 | else: |
| 640 | logger.info("Command executed sucessfully") |
| 641 | sendResponse({'success': True}) |
| 642 | |
| 643 | except Exception, e: |
| 644 | logger.warn("Command failed: %s" % e) |
| 645 | |
| 646 | executeThread = threading.Thread(target=executeCommand, args=(command, logger)) |
| 647 | executeThread.start() |