#!/bin/python3 ''' Created on Mar 30, 2014 author: tpweis file name: bot_halt.py The function is used to halt all bot activity on the machine running this command. For the purpose of stopping a specific bot, use the command bot_stop.py, which is accessed through scat_botstop.py. ''' import os import subprocess import time import sys sys.path.insert(0,'/sl/lib') from sleds_utilities import * def main(): "function main" print("Enter bot_halt") # Stop all bot process active on this machine. Since we don't have run time access to the # command line, we are going to stop all the bot processes that are owned by the user "sequencelogic". # other processes, like mongo, tomcat and k2, must be stopped first in order not to get an error return # because the below will only stop bot processes. # NOTE - the robot jar file path might use "sl" or "sequencelogic". For now, we will pkill each path # to the jar file. rc = "FAIL to halt all bots " user="sequencelogic" robotslong="/sequencelogic/bin/robot-1.0.0.one-jar.jar" robotsshort="/sl/bin/robot-1.0.0.one-jar.jar" p1 = subprocess.Popen(["pkill", "-U", user, "-f", robotslong]) p1 = subprocess.Popen(["pkill", "-U", user, "-f", robotsshort]) # this could take a little time - check n times before concluding failure for n in range(10): time.sleep(1) p2 = subprocess.Popen(["ps", "-U", user], stdout=subprocess.PIPE) # look for any robots p3 = subprocess.Popen(["grep", "robots"], stdin=p2.stdout, stdout=subprocess.PIPE) pdata = p3.communicate()[0] pdata = pdata.decode() pdata = pdata.rstrip() slscatlog('D',"Bot halt result: " + pdata) if (len(pdata) == 0): rc = "SUCCESS bots halted" break print(rc) exit() if __name__ == '__main__': # execute only if run as a script main()