]> git.wh0rd.org - home.git/commitdiff
gentoo-check-services: add --dry-run and fix whitespace handling
authorMike Frysinger <vapier@gentoo.org>
Thu, 20 Oct 2016 17:33:50 +0000 (10:33 -0700)
committerMike Frysinger <vapier@gentoo.org>
Thu, 20 Oct 2016 17:33:50 +0000 (10:33 -0700)
.bin/gentoo-check-services

index 97906a491faca49920c1633071ad47cea703c446..3b39c4dccefd6a30d5a5a4222db6b2bd7f009d84 100755 (executable)
@@ -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)