diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-14 14:29:19 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-14 14:29:19 +0000 |
commit | cf5f71ba15c897cd5768ea0dd644d1c9a6a4d4e2 (patch) | |
tree | d8561c28f4fe6e9ea54f4bb6dd61328358c34b32 /contrib | |
parent | 330e997d36e21a3a07e9259c38c3d6e13656da21 (diff) | |
download | gnunet-cf5f71ba15c897cd5768ea0dd644d1c9a6a4d4e2.tar.gz gnunet-cf5f71ba15c897cd5768ea0dd644d1c9a6a4d4e2.zip |
LRN: gnunet janitor -- another killall variant
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/Makefile.am | 13 | ||||
-rw-r--r-- | contrib/gnunet_janitor.py.in | 62 |
2 files changed, 69 insertions, 6 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am index b8dae1bbf..7ad8e542a 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am | |||
@@ -7,7 +7,8 @@ timeout_watchdog_SOURCES = \ | |||
7 | endif | 7 | endif |
8 | 8 | ||
9 | noinst_SCRIPTS = \ | 9 | noinst_SCRIPTS = \ |
10 | gnunet_pyexpect.py | 10 | gnunet_pyexpect.py \ |
11 | gnunet_janitor.py | ||
11 | 12 | ||
12 | dist_pkgdata_DATA = \ | 13 | dist_pkgdata_DATA = \ |
13 | gnunet-logo-color.png \ | 14 | gnunet-logo-color.png \ |
@@ -18,14 +19,14 @@ EXTRA_DIST = \ | |||
18 | hostlist.cgi \ | 19 | hostlist.cgi \ |
19 | hostlist.php \ | 20 | hostlist.php \ |
20 | report.sh \ | 21 | report.sh \ |
21 | gnunet_pyexpect.py.in | 22 | gnunet_pyexpect.py.in \ |
23 | gnunet_janitor.py.in | ||
22 | 24 | ||
23 | do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' | 25 | do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' |
24 | 26 | ||
25 | gnunet_pyexpect.py: gnunet_pyexpect.py.in Makefile | 27 | %.py: %.py.in Makefile |
26 | $(do_subst) < $(srcdir)/gnunet_pyexpect.py.in > gnunet_pyexpect.py | 28 | $(do_subst) < $(srcdir)/$< > $@ |
27 | chmod +x gnunet_pyexpect.py | 29 | chmod +x $@ |
28 | |||
29 | 30 | ||
30 | # init_gnunet_redhat \ | 31 | # init_gnunet_redhat \ |
31 | # init_gnunet_ubuntu \ | 32 | # init_gnunet_ubuntu \ |
diff --git a/contrib/gnunet_janitor.py.in b/contrib/gnunet_janitor.py.in new file mode 100644 index 000000000..c23cc2858 --- /dev/null +++ b/contrib/gnunet_janitor.py.in | |||
@@ -0,0 +1,62 @@ | |||
1 | #!@PYTHON@ | ||
2 | # This file is part of GNUnet. | ||
3 | # (C) 2011 Christian Grothoff (and other contributing authors) | ||
4 | # | ||
5 | # GNUnet is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published | ||
7 | # by the Free Software Foundation; either version 2, or (at your | ||
8 | # option) any later version. | ||
9 | # | ||
10 | # GNUnet is distributed in the hope that it will be useful, but | ||
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | # General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with GNUnet; see the file COPYING. If not, write to the | ||
17 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | # Boston, MA 02111-1307, USA. | ||
19 | # | ||
20 | # Finds any gnunet processes still running in the system and kills them | ||
21 | from __future__ import print_function | ||
22 | import os | ||
23 | import re | ||
24 | import subprocess | ||
25 | import sys | ||
26 | import shutil | ||
27 | import time | ||
28 | import signal | ||
29 | |||
30 | if os.name == 'nt': | ||
31 | from win32com.client import GetObject | ||
32 | WMI = GetObject('winmgmts:') | ||
33 | |||
34 | def get_process_list (): | ||
35 | result = [] | ||
36 | if os.name == 'nt': | ||
37 | processes = WMI.InstancesOf('Win32_Process') | ||
38 | for p in processes: | ||
39 | result.append ((p.Properties_('ProcessId').Value, re.sub (r'(.+)\.exe', r'\1', p.Properties_('Name').Value))) | ||
40 | else: | ||
41 | pids = [pid for pid in os.listdir('/proc') if pid.isdigit ()] | ||
42 | for pid in pids: | ||
43 | result.append ((pid, open (os.path.join ('/proc', pid, 'comm'), 'rb').read () | ||
44 | return result | ||
45 | |||
46 | def main (): | ||
47 | procs = get_process_list () | ||
48 | gnunet_procs = [] | ||
49 | for p in procs: | ||
50 | if re.match (r'gnunet-.+', p[1]): | ||
51 | gnunet_procs.append (p) | ||
52 | for p in gnunet_procs: | ||
53 | if re.match (r'gnunet-service-arm', p[1]): | ||
54 | print ("killing arm {0:5} {1}".format (p[0], p[1])) | ||
55 | os.kill (p[0], signal.SIGTERM) | ||
56 | for p in gnunet_procs: | ||
57 | if not re.match (r'gnunet-service-arm', p[1]): | ||
58 | print ("killing arm {0:5} {1}".format (p[0], p[1])) | ||
59 | os.kill (p[0], signal.SIGTERM) | ||
60 | |||
61 | if __name__ == '__main__': | ||
62 | sys.exit (main ()) \ No newline at end of file | ||