Add pid file to Environment
This commit adds the path of the PID file to the Environment. It also add it to the Security Manager since the PID file is deleted by a shutdown hook when the JVM is exited.
This commit is contained in:
parent
4f65130703
commit
3976724882
|
@ -193,32 +193,31 @@ public class Bootstrap {
|
|||
public static void main(String[] args) {
|
||||
System.setProperty("es.logger.prefix", "");
|
||||
INSTANCE = new Bootstrap();
|
||||
final String pidFile = System.getProperty("es.pidfile", System.getProperty("es-pidfile"));
|
||||
|
||||
if (pidFile != null) {
|
||||
try {
|
||||
PidFile.create(PathUtils.get(pidFile), true);
|
||||
} catch (Exception e) {
|
||||
String errorMessage = buildErrorMessage("pid", e);
|
||||
sysError(errorMessage, true);
|
||||
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;
|
||||
}
|
||||
|
||||
String stage = "Settings";
|
||||
|
||||
Settings settings = null;
|
||||
Environment environment = null;
|
||||
try {
|
||||
Tuple<Settings, Environment> tuple = initialSettings();
|
||||
settings = tuple.v1();
|
||||
environment = tuple.v2();
|
||||
|
||||
if (environment.pidFile() != null) {
|
||||
stage = "Pid";
|
||||
PidFile.create(environment.pidFile(), true);
|
||||
}
|
||||
|
||||
stage = "Logging";
|
||||
setupLogging(settings, environment);
|
||||
} catch (Exception e) {
|
||||
String errorMessage = buildErrorMessage("Setup", e);
|
||||
String errorMessage = buildErrorMessage(stage, e);
|
||||
sysError(errorMessage, true);
|
||||
System.exit(3);
|
||||
}
|
||||
|
@ -234,7 +233,7 @@ public class Bootstrap {
|
|||
logger.warn("jvm uses the client vm, make sure to run `java` with the server vm for best performance by adding `-server` to the command line");
|
||||
}
|
||||
|
||||
String stage = "Initialization";
|
||||
stage = "Initialization";
|
||||
try {
|
||||
if (!foreground) {
|
||||
Loggers.disableConsoleLogging();
|
||||
|
|
|
@ -67,7 +67,9 @@ public class Security {
|
|||
for (Path path : environment.dataWithClusterFiles()) {
|
||||
addPath(policy, path, "read,readlink,write,delete");
|
||||
}
|
||||
|
||||
if (environment.pidFile() != null) {
|
||||
addPath(policy, environment.pidFile().getParent(), "read,readlink,write,delete");
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,9 @@ public class Environment {
|
|||
|
||||
private final Path logsFile;
|
||||
|
||||
/** Path to the PID file (can be null if no PID file is configured) **/
|
||||
private final Path pidFile;
|
||||
|
||||
/** List of filestores on the system */
|
||||
private static final FileStore[] fileStores;
|
||||
|
||||
|
@ -106,6 +109,12 @@ public class Environment {
|
|||
} else {
|
||||
logsFile = homeFile.resolve("logs");
|
||||
}
|
||||
|
||||
if (settings.get("pidfile") != null) {
|
||||
pidFile = PathUtils.get(cleanPath(settings.get("pidfile")));
|
||||
} else {
|
||||
pidFile = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -151,6 +160,13 @@ public class Environment {
|
|||
return logsFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* The PID file location (can be null if no PID file is configured)
|
||||
*/
|
||||
public Path pidFile() {
|
||||
return pidFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the filestore associated with a Path.
|
||||
* <p>
|
||||
|
|
|
@ -70,6 +70,7 @@ public class SecurityTests extends ElasticsearchTestCase {
|
|||
settingsBuilder.put("path.plugins", path.resolve("plugins").toString());
|
||||
settingsBuilder.putArray("path.data", path.resolve("data1").toString(), path.resolve("data2").toString());
|
||||
settingsBuilder.put("path.logs", path.resolve("logs").toString());
|
||||
settingsBuilder.put("pidfile", path.resolve("test.pid").toString());
|
||||
Settings settings = settingsBuilder.build();
|
||||
|
||||
Environment environment = new Environment(settings);
|
||||
|
@ -105,5 +106,7 @@ public class SecurityTests extends ElasticsearchTestCase {
|
|||
assertTrue(permissions.implies(new FilePermission(fakeTmpDir.toString(), "read,readlink,write,delete")));
|
||||
// double check we overwrote java.io.tmpdir correctly for the test
|
||||
assertFalse(permissions.implies(new FilePermission(realTmpDir.toString(), "read")));
|
||||
// PID file: r/w
|
||||
assertTrue(permissions.implies(new FilePermission(environment.pidFile().toString(), "read,readlink,write,delete")));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue