(command, logger)
| 179 | logger.info("Performing command: %s" % command) |
| 180 | |
| 181 | def executeCommand(command, logger): |
| 182 | timeSleeping = 0.5 |
| 183 | #if shutdown send message to plugin |
| 184 | if action == "reboot" or action == "shutdown": |
| 185 | eventManager().fire(Events.SHUTTING_DOWN, {'status': action}) |
| 186 | timeSleeping = 1 |
| 187 | time.sleep(timeSleeping) #add a small delay to make sure the response is sent |
| 188 | |
| 189 | try: |
| 190 | p = sarge.run(command, stderr=sarge.Capture()) |
| 191 | if p.returncode != 0: |
| 192 | returncode = p.returncode |
| 193 | stderr_text = p.stderr.text |
| 194 | logger.warn("Command failed with return code %i: %s" % (returncode, stderr_text)) |
| 195 | if action == "reboot" or action == "shutdown": |
| 196 | eventManager().fire(Events.SHUTTING_DOWN, {'status': None}) |
| 197 | else: |
| 198 | logger.info("Command executed sucessfully") |
| 199 | |
| 200 | except Exception, e: |
| 201 | logger.warn("Command failed: %s" % e) |
| 202 | if command == "reboot" or command == "shutdown": |
| 203 | eventManager().fire(Events.SHUTTING_DOWN, {'status': None}) |
| 204 | |
| 205 | executeThread = threading.Thread(target=executeCommand, args=(command, logger)) |
| 206 | executeThread.start() |
nothing calls this directly
no test coverage detected