]>
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.
24 """Find all programs w/deleted paths."""
26 for pid
in os
.listdir('/proc'):
32 map = '/proc/%s/maps' % pid
33 if not os
.path
.exists(map):
34 print('skipping %s' % pid
)
38 for line
in open(map):
39 if not line
.endswith(' (deleted)\n'):
41 # b71c7000-b7307000 rw-s 00000000 00:04 17024337 /dev/zero (deleted)
42 addr
, perm
, offset
, dev
, inode
, path
= line
.split(' ', 5)
43 # Handle paths with spaces.
44 path
= path
.rsplit(' ', 2)[0]
45 if (path
== '/[aio]' or
46 path
.startswith('/SYSV') or
47 path
.startswith('/dev/shm/')):
51 old_paths
-= IGNORE_PATHS
55 cmdline
= open('/proc/%s/cmdline' % pid
).read().split('\0')
63 'old_paths': old_paths
,
68 # Mapping of known programs to their init.d scripts.
70 '/usr/sbin/acpid': 'acpid',
71 '/usr/sbin/apache2': 'apache2',
72 '/usr/sbin/atd': 'atd',
73 '/usr/sbin/bacula-fd': 'bacula-fd',
74 '/usr/sbin/cron': 'vixie-cron',
75 '/usr/sbin/crond': 'dcron',
76 '/usr/sbin/snmpd': 'snmpd',
77 '/usr/sbin/sshd': 'sshd',
78 '/usr/sbin/syslog-ng': 'syslog-ng',
79 '/usr/sbin/xinetd': 'xinetd',
80 '/usr/bin/daisydog': 'daisydog',
81 '/usr/bin/distccd': 'distccd',
82 '/usr/bin/monit': 'monit',
83 '/usr/bin/stunnel': 'stunnel',
84 '/usr/bin/tor': 'tor',
85 '/usr/bin/transmission-daemon': 'transmission-daemon',
86 '/usr/bin/mediatomb': 'mediatomb',
87 '/lib/systemd/systemd-udevd': 'udev',
88 '/usr/libexec/nrpe': 'nrpe',
89 '/usr/libexec/postfix/master': 'postfix',
90 'denyhosts.py': 'denyhosts',
91 'dropbear': 'dropbear',
93 'tlsdated': 'tlsdated',
95 def auto_restart(svcs
):
98 for pid
, svc
in svcs
.items():
99 if svc
['cmdline'][0] == '/sbin/agetty':
101 elif 'postgres:' in svc
['cmdline'][0]:
102 p
= os
.path
.basename(glob
.glob('/etc/runlevels/default/postgresql-*')[0])
104 elif svc
['cmdline'][0].startswith('metalog'):
105 restart
.add('metalog')
107 prog
= svc
['cmdline'][0]
108 if prog
.startswith('/usr/bin/python'):
109 prog
= os
.path
.basename(svc
['cmdline'][1])
111 init
= SERVICES
.get(prog
)
117 print('killing %s (%s)' % (pid
, svcs
[pid
]['cmdline'][0]))
118 os
.kill(pid
, signal
.SIGTERM
)
120 print('restarting %s' % init
)
121 os
.system('/etc/init.d/%s -q restart' % init
)
132 for pid
in svcs
.keys():
133 if svcs
[pid
]['cmdline'][0] == '/usr/sbin/sslh':
137 print('sslh needs restart')
140 for pid
, svc
in svcs
.items():
141 print(pid
, svc
['cmdline'])
142 print('\t%s' % '\n\t'.join(svc
['old_paths']))
146 parser
= argparse
.ArgumentParser(description
=__doc__
)
151 parser
= get_parser()
152 opts
= parser
.parse_args(argv
)
155 svcs
= auto_restart(svcs
)
159 if __name__
== '__main__':
160 exit(main(sys
.argv
[1:]))