]>
git.wh0rd.org - home.git/blob - .bin/gentoo-check-services
2 # -*- coding: utf-8 -*-
4 """Script for restarting services that refer to old/deleted libs."""
6 from __future__
import print_function
16 # Set of paths that are "OK" and safe to ignore.
20 '/usr/share/icons/Adwaita/icon-theme.cache',
21 '/usr/share/icons/gnome/icon-theme.cache',
22 '/usr/share/icons/hicolor/icon-theme.cache',
23 '/usr/share/mime/mime.cache',
28 """Find all programs w/deleted paths."""
30 for pid
in os
.listdir('/proc'):
36 map = '/proc/%s/maps' % pid
37 if not os
.path
.exists(map):
38 print('skipping %s' % pid
)
42 for line
in open(map):
43 if not line
.endswith(' (deleted)\n'):
45 # b71c7000-b7307000 rw-s 00000000 00:04 17024337 /dev/zero (deleted)
46 addr
, perm
, offset
, dev
, inode
, path
= line
.split(' ', 5)
47 # Handle paths with spaces.
48 path
= path
.lstrip().rsplit(' ', 2)[0]
49 if (path
== '/[aio]' or
50 path
.startswith('/memfd:') or
51 path
.startswith('/SYSV') or
52 path
.startswith('/dev/shm/') or
53 path
.startswith('/tmp/')):
57 old_paths
-= IGNORE_PATHS
61 cmdline
= open('/proc/%s/cmdline' % pid
).read().split('\0')
69 'old_paths': old_paths
,
74 # Mapping of known programs to their init.d scripts.
76 '/usr/sbin/acpid': 'acpid',
77 '/usr/sbin/apache2': 'apache2',
78 '/usr/sbin/atd': 'atd',
79 '/usr/sbin/bacula-fd': 'bacula-fd',
80 '/usr/sbin/cron': 'vixie-cron',
81 '/usr/sbin/crond': 'dcron',
82 '/usr/sbin/ntpd': 'ntpd',
83 '/usr/sbin/snmpd': 'snmpd',
84 '/usr/sbin/sshd': 'sshd',
85 '/usr/sbin/syslog-ng': 'syslog-ng',
86 '/usr/sbin/xinetd': 'xinetd',
87 '/usr/bin/daisydog': 'daisydog',
88 '/usr/bin/distccd': 'distccd',
89 '/usr/bin/monit': 'monit',
90 '/usr/bin/rsync': 'rsyncd',
91 '/usr/bin/stunnel': 'stunnel',
92 '/usr/bin/tor': 'tor',
93 '/usr/bin/transmission-daemon': 'transmission-daemon',
94 '/usr/bin/mediatomb': 'mediatomb',
95 '/lib/systemd/systemd-udevd': 'udev',
96 '/usr/libexec/nrpe': 'nrpe',
97 '//usr/libexec/postfix/master': 'postfix',
98 'denyhosts.py': 'denyhosts',
99 'dropbear': 'dropbear',
100 'galileo': 'galileo',
101 'tlsdated': 'tlsdated',
103 def auto_restart(opts
, svcs
):
106 for pid
, svc
in svcs
.items():
107 if svc
['cmdline'][0] == '/sbin/agetty':
109 elif 'postgres:' in svc
['cmdline'][0]:
110 p
= os
.path
.basename(glob
.glob('/etc/runlevels/default/postgresql-*')[0])
112 elif svc
['cmdline'][0].startswith('metalog'):
113 restart
.add('metalog')
115 prog
= svc
['cmdline'][0]
116 if prog
.startswith('/usr/bin/python'):
117 prog
= os
.path
.basename(svc
['cmdline'][1])
119 init
= SERVICES
.get(prog
)
125 print('killing %s (%s)' % (pid
, svcs
[pid
]['cmdline'][0]))
127 os
.kill(pid
, signal
.SIGTERM
)
129 print('restarting %s' % init
)
131 os
.system('/etc/init.d/%s -q restart' % init
)
143 for pid
in svcs
.keys():
144 if svcs
[pid
]['cmdline'][0] == '/usr/sbin/sslh':
148 print('sslh needs restart')
151 for pid
, svc
in svcs
.items():
152 print(pid
, svc
['cmdline'])
153 print('\t%s' % '\n\t'.join(svc
['old_paths']))
157 parser
= argparse
.ArgumentParser(description
=__doc__
)
158 parser
.add_argument('-n', '--dry-run', dest
='dryrun', action
='store_true',
159 help='Show what would be restarted (and why)')
164 parser
= get_parser()
165 opts
= parser
.parse_args(argv
)
168 svcs
= auto_restart(opts
, svcs
)
172 if __name__
== '__main__':
173 exit(main(sys
.argv
[1:]))