Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate the pidfile setting #45938

Merged
merged 6 commits into from
Aug 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testEnvironmentPaths() throws Exception {
esHome.resolve("data2").toString());
settingsBuilder.put(Environment.PATH_SHARED_DATA_SETTING.getKey(), esHome.resolve("custom").toString());
settingsBuilder.put(Environment.PATH_LOGS_SETTING.getKey(), esHome.resolve("logs").toString());
settingsBuilder.put(Environment.PIDFILE_SETTING.getKey(), esHome.resolve("test.pid").toString());
settingsBuilder.put(Environment.NODE_PIDFILE_SETTING.getKey(), esHome.resolve("test.pid").toString());
Settings settings = settingsBuilder.build();

Path fakeTmpDir = createTempDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private static Environment createEnvironment(
final Path configPath) {
Settings.Builder builder = Settings.builder();
if (pidFile != null) {
builder.put(Environment.PIDFILE_SETTING.getKey(), pidFile);
builder.put(Environment.NODE_PIDFILE_SETTING.getKey(), pidFile);
}
builder.put(initialSettings);
if (secureSettings != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public void apply(Settings value, Settings current, Settings previous) {
Environment.PATH_REPO_SETTING,
Environment.PATH_SHARED_DATA_SETTING,
Environment.PIDFILE_SETTING,
Environment.NODE_PIDFILE_SETTING,
NodeEnvironment.NODE_ID_SEED_SETTING,
Node.INITIAL_STATE_TIMEOUT_SETTING,
DiscoveryModule.DISCOVERY_TYPE_SETTING,
Expand Down
12 changes: 8 additions & 4 deletions server/src/main/java/org/elasticsearch/env/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public class Environment {
public static final Setting<List<String>> PATH_REPO_SETTING =
Setting.listSetting("path.repo", Collections.emptyList(), Function.identity(), Property.NodeScope);
public static final Setting<String> PATH_SHARED_DATA_SETTING = Setting.simpleString("path.shared_data", Property.NodeScope);
public static final Setting<String> PIDFILE_SETTING = Setting.simpleString("pidfile", Property.NodeScope);
public static final Setting<String> PIDFILE_SETTING = Setting.simpleString("pidfile", Property.Deprecated, Property.NodeScope);
public static final Setting<String> NODE_PIDFILE_SETTING = Setting.simpleString("node.pidfile", PIDFILE_SETTING, Property.NodeScope);

private final Settings settings;

Expand Down Expand Up @@ -154,8 +155,8 @@ public Environment(final Settings settings, final Path configPath) {
logsFile = homeFile.resolve("logs");
}

if (PIDFILE_SETTING.exists(settings)) {
pidFile = PathUtils.get(PIDFILE_SETTING.get(settings)).toAbsolutePath().normalize();
if (NODE_PIDFILE_SETTING.exists(settings) || PIDFILE_SETTING.exists(settings)) {
pidFile = PathUtils.get(NODE_PIDFILE_SETTING.get(settings)).toAbsolutePath().normalize();
} else {
pidFile = null;
}
Expand All @@ -179,7 +180,10 @@ public Environment(final Settings settings, final Path configPath) {
assert sharedDataFile != null;
finalSettings.put(Environment.PATH_SHARED_DATA_SETTING.getKey(), sharedDataFile.toString());
}
if (PIDFILE_SETTING.exists(settings)) {
if (NODE_PIDFILE_SETTING.exists(settings)) {
assert pidFile != null;
finalSettings.put(Environment.NODE_PIDFILE_SETTING.getKey(), pidFile.toString());
} else if (PIDFILE_SETTING.exists(settings)) {
assert pidFile != null;
finalSettings.put(Environment.PIDFILE_SETTING.getKey(), pidFile.toString());
}
Expand Down
17 changes: 16 additions & 1 deletion server/src/test/java/org/elasticsearch/env/EnvironmentTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.elasticsearch.env;

import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESTestCase;

Expand Down Expand Up @@ -174,13 +175,20 @@ public void testTempPathValidationWhenRegularFile() throws IOException {

// test that environment paths are absolute and normalized
public void testPathNormalization() throws IOException {
final Setting<String> pidFileSetting;
if (randomBoolean()) {
pidFileSetting = Environment.NODE_PIDFILE_SETTING;
} else {
pidFileSetting = Environment.PIDFILE_SETTING;
}

final Settings settings = Settings.builder()
.put(Environment.PATH_HOME_SETTING.getKey(), "home")
.put(Environment.PATH_DATA_SETTING.getKey(), "./home/../home/data")
.put(Environment.PATH_LOGS_SETTING.getKey(), "./home/../home/logs")
.put(Environment.PATH_REPO_SETTING.getKey(), "./home/../home/repo")
.put(Environment.PATH_SHARED_DATA_SETTING.getKey(), "./home/../home/shared_data")
.put(Environment.PIDFILE_SETTING.getKey(), "./home/../home/pidfile")
.put(pidFileSetting.getKey(), "./home/../home/pidfile")
.build();

// the above paths will be treated as relative to the working directory
Expand All @@ -205,6 +213,13 @@ public void testPathNormalization() throws IOException {

final String sharedDataPath = Environment.PATH_SHARED_DATA_SETTING.get(environment.settings());
assertPath(sharedDataPath, home.resolve("shared_data"));

final String pidFile = pidFileSetting.get(environment.settings());
assertPath(pidFile, home.resolve("pidfile"));

if (pidFileSetting.isDeprecated()) {
assertSettingDeprecationsAndWarnings(new Setting<?>[] { pidFileSetting });
}
}

private void assertPath(final String actual, final Path expected) {
Expand Down