Generate pid file even when running in foreground mode, closes #1553.

This commit is contained in:
Shay Banon 2011-12-21 05:28:28 +02:00
parent ffca91dda0
commit 91b60f1d2f
3 changed files with 28 additions and 12 deletions

View File

@ -114,20 +114,20 @@ launch_service()
es_parms="-Delasticsearch"
if [ "x$pidpath" != "x" ]; then
es_parms="$es_parms -Des-pidfile=$pidpath"
es_parms="$es_parms -Des.pidfile=$pidpath"
fi
# The es-daemon option will tell ElasticSearch to close stdout/stderr,
# but it's up to us not to background.
# The es-foreground option will tell ElasticSearch not to close stdout/stderr, but it's up to us not to background.
if [ "x$foreground" != "x" ]; then
es_parms="$es_parms -Des-foreground=yes"
es_parms="$es_parms -Des.foreground=yes"
exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \
org.elasticsearch.bootstrap.ElasticSearch
else
# Startup ElasticSearch, background it, and write the pid.
exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \
org.elasticsearch.bootstrap.ElasticSearch <&- &
[ ! -z "$pidpath" ] && printf '%d' $! > "$pidpath"
# no longer need to write the pid, the elasticsearch process will do it
# [ ! -z "$pidpath" ] && printf '%d' $! > "$pidpath"
fi
return $?

View File

@ -38,6 +38,7 @@ import org.elasticsearch.node.NodeBuilder;
import org.elasticsearch.node.internal.InternalSettingsPerparer;
import java.io.File;
import java.io.RandomAccessFile;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
@ -142,9 +143,28 @@ public class Bootstrap {
public static void main(String[] args) {
System.setProperty("es.logger.prefix", "");
bootstrap = new Bootstrap();
String pidFile = System.getProperty("es-pidfile");
final String pidFile = System.getProperty("es.pidfile", System.getProperty("es-pidfile"));
boolean foreground = System.getProperty("es-foreground") != null;
if (pidFile != null) {
try {
File fPidFile = new File(pidFile);
if (fPidFile.getParentFile() != null) {
FileSystemUtils.mkdirs(fPidFile.getParentFile());
}
RandomAccessFile rafPidFile = new RandomAccessFile(fPidFile, "rw");
rafPidFile.writeBytes(Long.toString(JvmInfo.jvmInfo().pid()) + "\n");
rafPidFile.close();
fPidFile.deleteOnExit();
} catch (Exception e) {
String errorMessage = buildErrorMessage("pid", e);
System.err.println(errorMessage);
System.err.flush();
System.exit(3);
}
}
boolean foreground = System.getProperty("es.foreground", System.getProperty("es-foreground")) != null;
// handle the wrapper system property, if its a service, don't run as a service
if (System.getProperty("wrapper.service", "XXX").equalsIgnoreCase("true")) {
foreground = false;
@ -180,10 +200,6 @@ public class Bootstrap {
}
bootstrap.setup(true, tuple);
if (pidFile != null) {
new File(pidFile).deleteOnExit();
}
stage = "Startup";
bootstrap.start();

View File

@ -11,7 +11,7 @@ public class ElasticSearchF {
}
public static void main(String[] args) {
System.setProperty("es-foreground", "yes");
System.setProperty("es.foreground", "yes");
Bootstrap.main(args);
}
}