def mpdsigjob(): mpd_set_my_id('mpdsigjob_') if len(argv) < 3 or argv[1] == '-h' or argv[1] == '--help': usage() username = mpd_get_my_username() if environ.has_key('UNIX_SOCKET'): conFD = int(environ['UNIX_SOCKET']) conSocket = fromfd(conFD, AF_UNIX, SOCK_STREAM) close(conFD) else: if environ.has_key('MPD_CON_EXT'): conExt = '_' + environ['MPD_CON_EXT'] else: conExt = '' consoleName = '/tmp/mpd2.console_' + username + conExt conSocket = socket(AF_UNIX, SOCK_STREAM) # note: UNIX socket try: conSocket.connect(consoleName) except Exception, errmsg: print 'mpdsigjob: cannot connect to local mpd (%s); possible causes:' % consoleName print ' 1. no mpd running on this host' print ' 2. mpd is running but was started without a "console" (-n option)' print 'you can start an mpd with the "mpd" command; to get help, run:' print ' mpd -h' exit(-1) # mpd_raise('cannot connect to local mpd; errmsg: %s' % (str(errmsg)) ) msgToSend = 'realusername=%s\n' % username mpd_send_one_line(conSocket, msgToSend)
def mpdlistjobs(): mpd_set_my_id('mpdlistjobs_') username = mpd_get_my_username() uname = '' jobid = '' sjobid = '' jobalias = '' sssPrintFormat = 0 if len(argv) > 1: aidx = 1 while aidx < len(argv): if argv[aidx] == '-h' or argv[aidx] == '--help': usage() if argv[aidx] == '-u': # or --user= uname = argv[aidx + 1] aidx += 2 elif argv[aidx].startswith('--user'): splitArg = argv[aidx].split('=') try: uname = splitArg[1] except: print 'mpdlistjobs: invalid argument:', argv[aidx] usage() aidx += 1 elif argv[aidx] == '-j': # or --jobid= jobid = argv[aidx + 1] aidx += 2 sjobid = jobid.split('@') # jobnum and originating host elif argv[aidx].startswith('--jobid'): splitArg = argv[aidx].split('=') try: jobid = splitArg[1] sjobid = jobid.split('@') # jobnum and originating host except: print 'mpdlistjobs: invalid argument:', argv[aidx] usage() aidx += 1 elif argv[aidx] == '-a': # or --alias= jobalias = argv[aidx + 1] aidx += 2 elif argv[aidx].startswith('--alias'): splitArg = argv[aidx].split('=') try: jobalias = splitArg[1] except: print 'mpdlistjobs: invalid argument:', argv[aidx] usage() aidx += 1 elif argv[aidx] == '--sss': sssPrintFormat = 1 aidx += 1 else: print 'unrecognized arg: %s' % argv[aidx] exit(-1) if environ.has_key('UNIX_SOCKET'): conFD = int(environ['UNIX_SOCKET']) conSocket = fromfd(conFD, AF_UNIX, SOCK_STREAM) close(conFD) else: if environ.has_key('MPD_CON_EXT'): conExt = '_' + environ['MPD_CON_EXT'] else: conExt = '' consoleName = '/tmp/mpd2.console_' + username + conExt conSocket = socket(AF_UNIX, SOCK_STREAM) # note: UNIX socket try: conSocket.connect(consoleName) except Exception, errmsg: print 'mpdlistjobs: cannot connect to local mpd (%s); possible causes:' % consoleName print ' 1. no mpd running on this host' print ' 2. mpd is running but was started without a "console" (-n option)' print 'you can start an mpd with the "mpd" command; to get help, run:' print ' mpd -h' exit(-1) msgToSend = 'realusername=%s\n' % username mpd_send_one_line(conSocket, msgToSend)
def mpdrun(): global nprocs, pgm, pgmArgs, mship, rship, argsFilename, delArgsFile, \ try0Locally, lineLabels, jobAlias, mergingOutput, conSocket global stdinGoesToWho, myExitStatus, manSocket, jobid, username, cwd, totalview global outXmlDoc, outXmlEC, outXmlFile, linesPerRank, gdb, gdbAttachJobid global execs, users, cwds, paths, args, envvars, limits, hosts, hostList global singinitPID, singinitPORT, doingBNR, myHost, myIP, myIfhn mpd_set_my_id('mpdrun_' + ` getpid() `) pgm = '' mship = '' rship = '' nprocs = 0 jobAlias = '' argsFilename = '' outExitCodesFilename = '' outXmlFile = '' outXmlDoc = '' outXmlEC = '' delArgsFile = 0 try0Locally = 1 lineLabels = 0 stdinGoesToWho = '0' mergingOutput = 0 hostList = [] gdb = 0 gdbAttachJobid = '' singinitPID = 0 singinitPORT = 0 doingBNR = 0 totalview = 0 myHost = gethostname() # default; may be chgd by -if arg myIfhn = '' known_rlimit_types = [ 'core', 'cpu', 'fsize', 'data', 'stack', 'rss', 'nproc', 'nofile', 'ofile', 'memlock', 'as', 'vmem' ] username = mpd_get_my_username() cwd = path.abspath(getcwd()) recvTimeout = 20 execs = {} users = {} cwds = {} paths = {} args = {} envvars = {} limits = {} hosts = {} get_args_from_cmdline( ) # verify args as much as possible before connecting to mpd (listenSocket, listenPort) = mpd_get_inet_listen_socket('', 0) signal(SIGALRM, sig_handler) if environ.has_key('MPDRUN_TIMEOUT'): jobTimeout = int(environ['MPDRUN_TIMEOUT']) elif environ.has_key('MPIEXEC_TIMEOUT'): jobTimeout = int(environ['MPIEXEC_TIMEOUT']) else: jobTimeout = 0 if environ.has_key('MPIEXEC_BNR'): doingBNR = 1 if environ.has_key('UNIX_SOCKET'): conFD = int(environ['UNIX_SOCKET']) conSocket = fromfd(conFD, AF_UNIX, SOCK_STREAM) close(conFD) else: if environ.has_key('MPD_CON_EXT'): conExt = '_' + environ['MPD_CON_EXT'] else: conExt = '' consoleName = '/tmp/mpd2.console_' + username + conExt conSocket = socket(AF_UNIX, SOCK_STREAM) # note: UNIX socket try: conSocket.connect(consoleName) except Exception, errmsg: print 'cannot connect to local mpd (%s); possible causes:' % consoleName print ' 1. no mpd running on this host' print ' 2. mpd is running but was started without a "console" (-n option)' print 'you can start an mpd with the "mpd" command; to get help, run:' print ' mpd -h' myExitStatus = -1 # used in main exit(myExitStatus) # really forces jump back into main # mpd_raise('cannot connect to local mpd; errmsg: %s' % (str(errmsg)) ) msgToSend = 'realusername=%s\n' % username mpd_send_one_line(conSocket, msgToSend) msgToSend = {'cmd': 'get_mpd_version'} mpd_send_one_msg(conSocket, msgToSend) msg = recv_one_msg_with_timeout(conSocket, recvTimeout) if not msg: mpd_raise('no msg recvd from mpd during version check') elif msg['cmd'] != 'mpd_version_response': mpd_raise('unexpected msg from mpd :%s:' % (msg)) if msg['mpd_version'] != mpd_version: mpd_raise('mpd version %s does not match mine %s' % (msg['mpd_version'], mpd_version))