-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Infer a JAVA_HOME path in DjangoBench
Summary: Try finding a JAVA_HOME path when running DjangoBench's DB role to reduce the possibility of Cassandra not being able to find JVM. Reviewed By: ahmadelyoussef Differential Revision: D61638351 fbshipit-source-id: 8539b77adb8d1341682d8250b21b2163ae0048c1
- Loading branch information
1 parent
1c13758
commit 717223b
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import pathlib | ||
import platform | ||
import subprocess | ||
|
||
|
||
def find_java_home() -> str: | ||
# Try finding a home path for java 8 | ||
candidates = [ | ||
"/usr/lib/jvm/java-1.8.0-openjdk", | ||
"/usr/lib/jvm/java-1.8.0-jre", | ||
"/usr/lib/jvm/java-8-openjdk", | ||
"/usr/lib/jvm/java-8-jre", | ||
"/usr/lib/jvm/openjdk-8", | ||
"/usr/lib/jvm/jre-1.8.0", | ||
"/usr/lib/jvm/jre-1.8.0-openjdk", | ||
] | ||
archname = platform.machine() | ||
if archname == "x86_64": | ||
archname = "amd64" | ||
elif archname == "aarch64": | ||
archname = "arm64" | ||
for path in candidates: | ||
if os.path.exists(f"{path}/bin/java"): | ||
return path | ||
path_with_arch = f"{path}-{archname}" | ||
if os.path.exists(f"{path_with_arch}/bin/java"): | ||
return path_with_arch | ||
# If none of the candidate exists, try find through `java` command | ||
try: | ||
java_path = subprocess.check_output(["which", "java"], text=True).strip() | ||
java_home = str(pathlib.Path(os.path.realpath(java_path)).parents[1]) | ||
except subprocess.CalledProcessError: | ||
java_home = "" | ||
|
||
return java_home | ||
|
||
|
||
if __name__ == "__main__": | ||
print(find_java_home()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters