📄 mpdcheck.py
字号:
print msg.replace(' ','') fipaddr1 = 0 try: ghbnf = gethostbyname_ex(fqhn1) if verbose: print "gethostbyname_ex: ", ghbnf fipaddr1 = ghbnf[2][0] if fipaddr1.startswith('127'): msg = """ ********** Your fully qualified hostname resolves to 127.0.0.1, which is the IP address reserved for localhost. This likely means that you have a line similar to this one in your /etc/hosts file: 127.0.0.1 $fqhn This should be perhaps changed to the following: 127.0.0.1 localhost.localdomain localhost ********** """ try: ghbaf = gethostbyaddr(fipaddr1) except: print "*** gethostbyaddr failed for this hosts's IP %s" % (uipaddr1) except: if long_messages: msg = """ ********** The system call gethostbyname(3) failed to resolve your fully qualified hostname, or $fqhn. This can be caused by missing info from your /etc/hosts file or your system not having correctly configured name resolvers, or by your IP address not existing in resolution services. If you run DNS, please check and make sure that your DNS server has the correct forward A record set up for yout machine's hostname. If you are not using DNS and are only using hosts files, please check that a line similar to the one below exists in your /etc/hosts file: $ipaddr $fqhn If you intend to use DNS but you are not sure that it is correctly configured, please check that the file /etc/resolv.conf contains entries similar to the following: nameserver 1.2.3.4 where 1.2.3.4 is an actual IP of one of your nameservers. ********** """ else: msg = "*** gethostbyname_ex failed for host %s" % (fqhn1) print msg.replace(' ','') if verbose: print 'checking that IP addrs resolve to same host' if uipaddr1 and fipaddr1 and uipaddr1 != fipaddr1: msg = """ ********** Your fully qualified and unqualified names do not resolve to the same IP. This likely means that your DNS domain name is not set correctly. This might be fixed by adding a line similar to the following to your /etc/hosts: $ipaddr $fqhn $uqdn ********** """ print msg.replace(' ','') if verbose: print 'now do some gethostbyaddr and gethostbyname_ex for machines in hosts file' # See if we can do gethostXXX, etc. for hosts in hostsFromFile for host in hostsFromFile: uqhn2 = host fqhn2 = getfqdn(uqhn2) uipaddr2 = 0 if verbose: print 'checking gethostbyXXX for unqualified %s' % (uqhn2) try: ghbnu = gethostbyname_ex(uqhn2) if verbose: print "gethostbyname_ex: ", ghbnu uipaddr2 = ghbnu[2][0] try: ghbau = gethostbyaddr(uipaddr2) except: print "*** gethostbyaddr failed for remote hosts's IP %s" % (fipaddr2) except: print "*** gethostbyname_ex failed for host %s" % (fqhn2) if verbose: print 'checking gethostbyXXX for qualified %s' % (uqhn2) try: ghbnf = gethostbyname_ex(fqhn2) if verbose: print "gethostbyname_ex: ", ghbnf fipaddr2 = ghbnf[2][0] if uipaddr2 and fipaddr2 != uipaddr2: print "*** ipaddr via uqn (%s) does not match via fqn (%s)" % (uipaddr2,fipaddr2) try: ghbaf = gethostbyaddr(fipaddr2) except: print "*** gethostbyaddr failed for remote hosts's IP %s" % (fipaddr2) except: print "*** gethostbyname_ex failed for host %s" % (fqhn2) # see if we can run /bin/date on remote hosts if not do_ssh: exit(0) for host in hostsFromFile: cmd = "ssh %s -x -n /bin/echo hello" % (host) if verbose: print 'trying: %s' % (cmd) runner = Popen3(cmd,1,0) runout = runner.fromchild runerr = runner.childerr runin = runner.tochild runpid = runner.pid try: (readyFDs,unused1,unused2) = select([runout],[],[],9) except Exception, data: print 'select 1 error: %s ; %s' % ( data.__class__, data) exit(-1) if len(readyFDs) == 0: print '** ssh timed out to %s' % (host) line = '' failed = 0 if runout in readyFDs: line = runout.readline() if not line.startswith('hello'): failed = 1 else: failed = 1 if failed: print '** ssh failed to %s' % (host) print '** here is the output:' if line: print line, done = 0 fds = [runout,runerr] while not done: try: (readyFDs,unused1,unused2) = select(fds,[],[],1) except Exception, data: print 'select 2 error: %s ; %s' % ( data.__class__, data) exit(-1) if runout in readyFDs: line = runout.readline() if line: print line, else: fds.remove(runout) elif runerr in readyFDs: line = runerr.readline() if line: print line, else: fds.remove(runerr) else: done = 1 try: kill(runpid,SIGKILL) runout.close() runerr.close() runin.close() except: pass if failed: exit(-1) # see if we can run mpdcheck on remote hosts for host in hostsFromFile: cmd1 = path.join(fullDirName,'mpdcheck.py') + ' -s' if verbose: print 'starting server: %s' % (cmd1) runner1 = Popen3(cmd1,1,0) runout1 = runner1.fromchild runerr1 = runner1.childerr runin1 = runner1.tochild runpid1 = runner1.pid try: (readyFDs,unused1,unused2) = select([runout1],[],[],9) except Exception, data: print 'select 3 error: %s ; %s' % ( data.__class__, data) exit(-1) if len(readyFDs) == 0: print '** timed out waiting for local server to produce output' line = '' failed = 0 port = 0 if runout1 in readyFDs: line = runout1.readline() if line.startswith('server listening at '): port = line.rstrip().split(' ')[-1] else: failed = 1 else: failed = 1 if failed: print 'could not start mpdcheck server' print 'here is the output:' if line: print line, done = 0 fds = [runout1,runerr1] while not done: try: (readyFDs,unused1,unused2) = select(fds,[],[],1) except Exception, data: print 'select 4 error: %s ; %s' % ( data.__class__, data) exit(-1) if runout in readyFDs: line = runout.readline() if line: print line, else: fds.remove(runout) elif runerr in readyFDs: line = runerr.readline() if line: print line, else: fds.remove(runerr) else: done = 1 if failed: try: kill(runpid1,SIGKILL) except: pass exit(-1) cmd2 = "ssh %s -x -n %s%smpdcheck.py -c %s %s" % (host,fullDirName,path.sep,fqhn1,port) if verbose: print 'starting client: %s' % (cmd2) runner2 = Popen3(cmd2,1,0) runout2 = runner2.fromchild runerr2 = runner2.childerr runin2 = runner2.tochild runpid2 = runner2.pid try: (readyFDs,unused1,unused2) = select([runout2],[],[],9) except Exception, data: print 'select 3 error: %s ; %s' % ( data.__class__, data) exit(-1) if len(readyFDs) == 0: print '** timed out waiting for client on %s to produce output' % (host) line = '' failed = 0 port = 0 if runout2 in readyFDs: line = runout2.readline() if not line.startswith('client successfully recvd'): failed = 1 else: failed = 1 if failed: print 'client on %s failed to access the server' % (host) print 'here is the output:' if line: print line, done = 0 fds = [runout2,runerr2] while not done: try: (readyFDs,unused1,unused2) = select(fds,[],[],1) except Exception, data: print 'select 4 error: %s ; %s' % ( data.__class__, data) exit(-1) if runout2 in readyFDs: line = runout2.readline() if line: print line, else: fds.remove(runout2) elif runerr2 in readyFDs: line = runerr2.readline() if line: print line, else: fds.remove(runerr2) else: done = 1 try: kill(runpid2,SIGKILL) except: pass if failed: try: kill(runpid1,SIGKILL) except: pass exit(-1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -