aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/Makefile.am13
-rw-r--r--contrib/gnunet_janitor.py.in62
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 = \
7endif 7endif
8 8
9noinst_SCRIPTS = \ 9noinst_SCRIPTS = \
10 gnunet_pyexpect.py 10 gnunet_pyexpect.py \
11 gnunet_janitor.py
11 12
12dist_pkgdata_DATA = \ 13dist_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
23do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g' 25do_subst = $(SED) -e 's,[@]PYTHON[@],$(PYTHON),g'
24 26
25gnunet_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
21from __future__ import print_function
22import os
23import re
24import subprocess
25import sys
26import shutil
27import time
28import signal
29
30if os.name == 'nt':
31 from win32com.client import GetObject
32 WMI = GetObject('winmgmts:')
33
34def 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
46def 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
61if __name__ == '__main__':
62 sys.exit (main ()) \ No newline at end of file