<s> import ConfigParser <EOL> import os <EOL> import re <EOL> import subprocess <EOL> import sys <EOL> from supervisor import childutils <EOL> JOB_INSTANCES_REGEX = re . compile ( '<STR_LIT>' ) <EOL> def handle_event ( payload ) : <EOL> '''<STR_LIT>''' <EOL> pheaders , pdata = childutils . eventdata ( payload + '<STR_LIT:\n>' ) <EOL> name_list = pheaders [ '<STR_LIT>' ] . split ( '<STR_LIT>' ) <EOL> if len ( name_list ) == <NUM_LIT:3> : <EOL> service , cluster , job = name_list <EOL> else : <EOL> return None <EOL> childutils . pcomm . stderr ( childutils . get_asctime ( ) + '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % pheaders ) <EOL> supervisor_config_path = '<STR_LIT>' % os . path . dirname ( __file__ ) <EOL> if not os . path . exists ( supervisor_config_path ) : <EOL> childutils . pcomm . stderr ( '<STR_LIT>' ) <EOL> parser = ConfigParser . SafeConfigParser ( ) <EOL> parser . read ( [ supervisor_config_path ] ) <EOL> sys . path . append ( '<STR_LIT>' % os . path . dirname ( __file__ ) ) <EOL> from rpcinterface import DEFAULT_APP_ROOT <EOL> app_root = parser . get ( '<STR_LIT>' , '<STR_LIT>' , DEFAULT_APP_ROOT ) <EOL> reg_expr = JOB_INSTANCES_REGEX . match ( job ) <EOL> job = reg_expr . group ( '<STR_LIT>' ) <EOL> if reg_expr . group ( '<STR_LIT>' ) : <EOL> instance_id = reg_expr . group ( '<STR_LIT>' ) <EOL> service_root = '<STR_LIT>' % ( app_root , service , cluster , job , instance_id ) <EOL> else : <EOL> service_root = '<STR_LIT>' % ( app_root , service , cluster , job ) <EOL> if not os . path . exists ( '<STR_LIT>' % service_root ) : <EOL> childutils . pcomm . stderr ( '<STR_LIT>' % service ) <EOL> return None <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' % service_root ] <EOL> subprocess . call ( cmd ) <EOL> def main ( ) : <EOL> process_state_events = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> while True : <EOL> headers , payload = childutils . listener . wait ( ) <EOL> if headers [ '<STR_LIT>' ] in process_state_events : <EOL> handle_event ( payload ) <EOL> childutils . listener . ok ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
