chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r1042276 - /incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/PidFile.java
Date Sun, 05 Dec 2010 02:49:28 GMT
Author: eyang
Date: Sun Dec  5 02:49:28 2010
New Revision: 1042276

URL: http://svn.apache.org/viewvc?rev=1042276&view=rev
Log:
CHUKWA-7. Handle pid in /tmp in case CHUKWA_HOME is not defined. (Ari Rabkin via Eric Yang)

Modified:
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/PidFile.java

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/PidFile.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/PidFile.java?rev=1042276&r1=1042275&r2=1042276&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/PidFile.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/util/PidFile.java Sun Dec  5
02:49:28 2010
@@ -31,6 +31,22 @@ public class PidFile extends Thread {
   private static Log log = LogFactory.getLog(PidFile.class);
   private static FileLock lock = null;
   private static FileOutputStream pidFileOutput = null;
+  private static final String DEFAULT_CHUKWA_HOME;
+  
+  static {
+      //use /tmp as a default, only if we can't create tmp files via Java.
+    File chukwaHome = new File(System.getProperty("java.io.tmpdir"), "chukwa");
+    try {
+      File tmpFile = File.createTempFile("chukwa", "discovertmp");
+      File tmpDir = tmpFile.getParentFile();
+      tmpFile.delete();
+      chukwaHome = new File(tmpDir, "chukwa");
+      chukwaHome.mkdir();
+    } catch(IOException e) {
+    } finally {    
+      DEFAULT_CHUKWA_HOME = chukwaHome.getAbsolutePath();
+    }
+  };
 
   public PidFile(String name) {
     this.name = name;
@@ -47,6 +63,9 @@ public class PidFile extends Thread {
     String[] items = pidLong.split("@");
     String pid = items[0];
     String chukwaPath = System.getProperty("CHUKWA_HOME");
+    if(chukwaPath == null) {
+      chukwaPath = DEFAULT_CHUKWA_HOME;
+    }
     StringBuffer pidFilesb = new StringBuffer();
     String pidDir = System.getenv("CHUKWA_PID_DIR");
     if (pidDir == null) {
@@ -86,6 +105,9 @@ public class PidFile extends Thread {
 
   public void clean() {
     String chukwaPath = System.getenv("CHUKWA_HOME");
+    if(chukwaPath == null) {
+      chukwaPath = DEFAULT_CHUKWA_HOME;
+    }
     StringBuffer pidFilesb = new StringBuffer();
     String pidDir = System.getenv("CHUKWA_PID_DIR");
     if (pidDir == null) {



Mime
View raw message