I'd like to have a feature in elasticsearch server that allows to perform a graceful stop or restart.

Basically after executing a systemctl stop/restart command I would like that the current pending requests are completed first (with a customizable timeout), while not accepting any new request.

This would simplify the draining of inflight requests, without forcing the application to retry connections abruptly closed

You already have something similar with https://www.elastic.co/guide/en/cloud/current/ec-maintenance-mode-deployments.html - but it should work with base elasticsearch server too.


server/src/main/java/org/elasticsearch/node/Node.java
)
            .filter(Optional::isPresent)
            .map(Optional::get)
            .toList();
        if (recoveryPlannerServices.isEmpty()) {
            return new PeerOnlyRecoveryPlannerService();
        } else if (recoveryPlannerServices.size() > 1) {
            throw new IllegalStateException("Expected a single RecoveryPlannerService but got: " + recoveryPlannerServices.size());
        }
        return recoveryPlannerServices.get(0);
    }
    private WriteLoadForecaster getWriteLoadForecaster(ThreadPool threadPool, Settings settings, ClusterSettings clusterSettings) {
        final List<ClusterPlugin> clusterPlugins = pluginsService.filterPlugins(ClusterPlugin.class);
        final List<WriteLoadForecaster> writeLoadForecasters = clusterPlugins.stream()
            .flatMap(clusterPlugin -> clusterPlugin.createWriteLoadForecasters(threadPool, settings, clusterSettings).stream())
            .toList();
        if (writeLoadForecasters.isEmpty()) {
            return WriteLoadForecaster.DEFAULT;
        }
        if (writeLoadForecasters.size() > 1) {
            throw new IllegalStateException("A single WriteLoadForecaster was expected but got: " + writeLoadForecasters);
        }
        return writeLoadForecasters.get(0);
    }
    private PersistedClusterStateService newPersistedClusterStateService(
        NamedXContentRegistry xContentRegistry,
        ClusterSettings clusterSettings,
        ThreadPool threadPool
    ) {
        final List<ClusterCoordinationPlugin.PersistedClusterStateServiceFactory> persistedClusterStateServiceFactories = pluginsService