diff options
author | Tim Burke <tim.burke@gmail.com> | 2019-07-15 18:07:01 -0700 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2019-08-15 10:34:54 -0700 |
commit | 27e7e80e922a51f3f4d21aa4d58f84fa9b5c6621 (patch) | |
tree | b8dabe95d1f65110217304deb3b1f78974f87f98 /bin | |
parent | 4643412bd11a7151bf56a590c260ccab9e1725bf (diff) | |
download | swift-27e7e80e922a51f3f4d21aa4d58f84fa9b5c6621.tar.gz |
py3: fix up swift-orphans
Change-Id: Id1280abd92e8bb02fcaa4701a0e9d211d9d6e33e
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/swift-orphans | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/bin/swift-orphans b/bin/swift-orphans index d2a3889ad..ed2b896fa 100755 --- a/bin/swift-orphans +++ b/bin/swift-orphans @@ -15,6 +15,7 @@ from __future__ import print_function import optparse import os +import re import signal import subprocess import sys @@ -56,27 +57,30 @@ Example (sends SIGTERM to all orphaned Swift processes older than two hours): pids.append(open(os.path.join(root, name)).read().strip()) pids.extend(subprocess.Popen( ['ps', '--ppid', pids[-1], '-o', 'pid', '--no-headers'], - stdout=subprocess.PIPE).communicate()[0].split()) + stdout=subprocess.PIPE).communicate()[0].decode().split()) listing = [] + swift_cmd_re = re.compile( + '^/usr/bin/python[23]? /usr(?:/local)?/bin/swift-') for line in subprocess.Popen( ['ps', '-eo', 'etime,pid,args', '--no-headers'], - stdout=subprocess.PIPE).communicate()[0].split('\n'): + stdout=subprocess.PIPE).communicate()[0].split(b'\n'): if not line: continue hours = 0 try: - etime, pid, args = line.split(None, 2) + etime, pid, args = line.decode('ascii').split(None, 2) except ValueError: sys.exit('Could not process ps line %r' % line) if pid in pids: continue - if (not args.startswith('/usr/bin/python /usr/bin/swift-') and - not args.startswith('/usr/bin/python /usr/local/bin/swift-')) or \ - 'swift-orphans' in args or \ - 'once' in args.split(): + if any([ + not swift_cmd_re.match(args), + 'swift-orphans' in args, + 'once' in args.split(), + ]): continue - args = args.split('-', 1)[1] + args = args.split('swift-', 1)[1] etime = etime.split('-') if len(etime) == 2: hours = int(etime[0]) * 24 @@ -105,11 +109,11 @@ Example (sends SIGTERM to all orphaned Swift processes older than two hours): args_len = max(args_len, len(args)) args_len = min(args_len, 78 - hours_len - pid_len) - print(('%%%ds %%%ds %%s' % (hours_len, pid_len)) % - ('Hours', 'PID', 'Command')) + print('%*s %*s %s' % + (hours_len, 'Hours', pid_len, 'PID', 'Command')) for hours, pid, args in listing: - print(('%%%ds %%%ds %%s' % (hours_len, pid_len)) % - (hours, pid, args[:args_len])) + print('%*s %*s %s' % + (hours_len, hours, pid_len, pid, args[:args_len])) if options.signal: try: |