]>
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/sbin/smbd': 'samba',
92 '/usr/bin/stunnel': 'stunnel',
93 '/usr/bin/tor': 'tor',
94 '/usr/bin/transmission-daemon': 'transmission-daemon',
95 '/usr/bin/mediatomb': 'mediatomb',
96 '/lib/systemd/systemd-udevd': 'udev',
97 '/usr/libexec/nrpe': 'nrpe',
98 '//usr/libexec/postfix/master': 'postfix',
99 'denyhosts.py': 'denyhosts',
100 'dropbear': 'dropbear',
101 'galileo': 'galileo',
102 'tlsdated': 'tlsdated',
104 def auto_restart(opts
, svcs
):
107 for pid
, svc
in svcs
.items():
108 if svc
['cmdline'][0] == '/sbin/agetty':
110 elif 'postgres:' in svc
['cmdline'][0]:
111 p
= os
.path
.basename(glob
.glob('/etc/runlevels/default/postgresql-*')[0])
113 elif svc
['cmdline'][0].startswith('metalog'):
114 restart
.add('metalog')
116 prog
= svc
['cmdline'][0]
117 if prog
.startswith('/usr/bin/python'):
118 prog
= os
.path
.basename(svc
['cmdline'][1])
120 init
= SERVICES
.get(prog
)
126 print('killing %s (%s)' % (pid
, svcs
[pid
]['cmdline'][0]))
128 os
.kill(pid
, signal
.SIGTERM
)
130 print('restarting %s' % init
)
132 os
.system('/etc/init.d/%s -q restart' % init
)
144 for pid
in svcs
.keys():
145 if svcs
[pid
]['cmdline'][0] == '/usr/sbin/sslh':
149 print('sslh needs restart')
152 for pid
, svc
in svcs
.items():
153 print(pid
, svc
['cmdline'])
154 print('\t%s' % '\n\t'.join(svc
['old_paths']))
158 parser
= argparse
.ArgumentParser(description
=__doc__
)
159 parser
.add_argument('-n', '--dry-run', dest
='dryrun', action
='store_true',
160 help='Show what would be restarted (and why)')
165 parser
= get_parser()
166 opts
= parser
.parse_args(argv
)
169 svcs
= auto_restart(opts
, svcs
)
173 if __name__
== '__main__':
174 exit(main(sys
.argv
[1:]))