From 967c0e546a90ce57592f30d2518d58e5aa2f0f0e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 20 Oct 2016 10:33:50 -0700 Subject: [PATCH] gentoo-check-services: add --dry-run and fix whitespace handling --- .bin/gentoo-check-services | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.bin/gentoo-check-services b/.bin/gentoo-check-services index 97906a4..3b39c4d 100755 --- a/.bin/gentoo-check-services +++ b/.bin/gentoo-check-services @@ -41,10 +41,11 @@ def find_svcs(): # b71c7000-b7307000 rw-s 00000000 00:04 17024337 /dev/zero (deleted) addr, perm, offset, dev, inode, path = line.split(' ', 5) # Handle paths with spaces. - path = path.rsplit(' ', 2)[0] + path = path.lstrip().rsplit(' ', 2)[0] if (path == '/[aio]' or path.startswith('/SYSV') or - path.startswith('/dev/shm/')): + path.startswith('/dev/shm/') or + path.startswith('/tmp/')): continue old_paths.add(path) @@ -92,7 +93,7 @@ SERVICES = { 'galileo': 'galileo', 'tlsdated': 'tlsdated', } -def auto_restart(svcs): +def auto_restart(opts, svcs): kill = set() restart = set() for pid, svc in svcs.items(): @@ -115,13 +116,16 @@ def auto_restart(svcs): if kill or restart: for pid in kill: print('killing %s (%s)' % (pid, svcs[pid]['cmdline'][0])) - os.kill(pid, signal.SIGTERM) + if not opts.dryrun: + os.kill(pid, signal.SIGTERM) for init in restart: print('restarting %s' % init) - os.system('/etc/init.d/%s -q restart' % init) + if not opts.dryrun: + os.system('/etc/init.d/%s -q restart' % init) - time.sleep(1) - svcs = find_svcs() + if not opts.dryrun: + time.sleep(1) + svcs = find_svcs() return svcs @@ -144,6 +148,8 @@ def summarize(svcs): def get_parser(): parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('-n', '--dry-run', dest='dryrun', action='store_true', + help='Show what would be restarted (and why)') return parser @@ -152,7 +158,7 @@ def main(argv): opts = parser.parse_args(argv) svcs = find_svcs() - svcs = auto_restart(svcs) + svcs = auto_restart(opts, svcs) summarize(svcs) -- 2.39.2