bigdata-dev team mailing list archive
-
bigdata-dev team
-
Mailing list archive
-
Message #00012
[Merge] lp:~bigdata-dev/charms/trusty/hdp-hive/cs-jps-quickfix into lp:charms/trusty/hdp-hive
Cory Johns has proposed merging lp:~bigdata-dev/charms/trusty/hdp-hive/cs-jps-quickfix into lp:charms/trusty/hdp-hive.
Requested reviews:
Big Data Charmers (bigdata-charmers)
For more details, see:
https://code.launchpad.net/~bigdata-dev/charms/trusty/hdp-hive/cs-jps-quickfix/+merge/250935
Work around the upstream JPS issue (https://bugs.launchpad.net/ubuntu/+source/openjdk-6/+bug/1417962)
--
Your team Juju Big Data Development is subscribed to branch lp:~bigdata-dev/charms/trusty/hdp-hive/cs-jps-quickfix.
=== modified file 'hooks/bdutils.py'
--- hooks/bdutils.py 2014-08-15 13:20:52 +0000
+++ hooks/bdutils.py 2015-02-25 14:49:48 +0000
@@ -1,4 +1,5 @@
#!/usr/bin/python
+import re
import os
import pwd
import grp
@@ -124,23 +125,25 @@
m = ll[0]+" = "+ll[1].strip().strip(';').strip("\"").strip()
#log ("==> {} ".format("\""+m+"\""))
os.environ[ll[0]] = ll[1].strip().strip(';').strip("\"").strip()
-
+
+
+def jps(name):
+ """
+ Get PIDs for named Java processes, for any user.
+ """
+ pat = re.sub(r'^(.)', r'^[^ ]*java .*[\1]', name)
+ try:
+ output = subprocess.check_output(['sudo', 'pgrep', '-f', pat])
+ except subprocess.CalledProcessError:
+ return []
+ return map(int, filter(None, map(str.strip, output.split('\n'))))
+
+
def is_jvm_service_active(processname):
- cmd=["jps"]
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
- out, err = p.communicate()
- if err == None and str(out).find(processname) != -1:
- return True
- else:
- return False
+ return jps(processname) != []
+
def kill_java_process(process):
- cmd=["jps"]
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
- out, err = p.communicate()
- cmd = out.split()
- for i in range(0, len(cmd)):
- if cmd[i] == process:
- pid = int(cmd[i-1])
- os.kill(pid, signal.SIGTERM)
+ for pid in jps(process):
+ os.kill(pid, signal.SIGTERM)
return 0
Follow ups