# Elasticsearch service fails to start

**URL:** <https://discuss.elastic.co/t/elasticsearch-service-fails-to-start/113470>\
**Category:** Elasticsearch\
**Created:** [December 28, 2017, 3:56pm UTC](https://discuss.elastic.co/t/elasticsearch-service-fails-to-start/113470 "2017-12-28T15:56:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShilpiRachna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shilpirachna/32/42261_2.png) [@ShilpiRachna](https://discuss.elastic.co/u/ShilpiRachna)\
**Post date:** [December 28, 2017, 3:56pm UTC](https://discuss.elastic.co/t/elasticsearch-service-fails-to-start/113470/1 "2017-12-28T15:56:47Z")

</div>

We are using Elasticsearch version 5.4.1 on Windows 10.

We have an automation that does the following:

1. Installs Java at a known location (JAVA\_HOME is always defined in System environment variable)

2. Install Elasticsearch using "elasticsearch-service.bat install"  
Output:  
[Info @12:06:16.709] Installing service : "elasticsearch-service-x64"  
[Info @12:06:16.709] Using JAVA\_HOME (64-bit): "C:\Program Files\Java\jre1.8.0\_151"  
[Info @12:06:16.709] The service 'elasticsearch-service-x64' has been installed.

3. Start Elasticsearch using "elasticsearch-service.bat start"  
It fails with the following error:  
_2017-12-26 12:06:18 Commons Daemon procrun stderr initialized_  
_The data area passed to a system call is too small._  
_Failed to start service_

I read that the issue is cause by JAVA\_HOME environment variable not being defined as a System variable. I have verified that it is set correctly. In fact, the issue repros even if JAVA\_HOME is correctly set even before running the automation and we install JAVA at the specified location.

**However, the issue does not repro if Java is already installed.**

Also, verified that heap size is set correctly in the JVM.options.

This issue is intermittent. What else should I check / do to fix this issue?

---

<div class="post-metadata">

**Author:** ![Martijn\_Laarman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman/32/4410_2.png) [@Martijn\_Laarman](https://discuss.elastic.co/u/Martijn_Laarman)\
**Post date:** [December 28, 2017, 6:48pm UTC](https://discuss.elastic.co/t/elasticsearch-service-fails-to-start/113470/2 "2017-12-28T18:48:24Z")

</div>

It does sound like JAVA\_HOME is not available

Are you able to share the following logs?

```
logs\elasticsearch-service-x64-stdout.*.log
logs\elasticsearch-service-x64.*.log

```

Can you share a little bit more what kind of automation is running and how you are verifying JAVA\_HOME is set correctly?

---

<div class="post-metadata">

**Author:** ![ShilpiRachna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shilpirachna/32/42261_2.png) [@ShilpiRachna](https://discuss.elastic.co/u/ShilpiRachna)\
**Post date:** [December 29, 2017, 7:01am UTC](https://discuss.elastic.co/t/elasticsearch-service-fails-to-start/113470/3 "2017-12-29T07:01:20Z")

</div>

Hi Martijn,

It is a .Net application that installs Elasticsearch as a pre-requisite. Copying the relevant Code snippet below:

```
    public void Install(string esHome, IActivityLog logger)
    {
        Action installStatusCallback = () =>
        {
            if (!WindowsServiceManagement.IsServiceInstalled(ComputerInfo.MachineName, ElasticsearchConstants.ElasticsearchServiceName))
            {
                logger.Info($"Waiting for Elasticsearch operation to complete...");
                throw new ElasticsearchOperationTimedoutException($"Elasticsearch operation was timedout.");
            }
        };

        InvokeServiceBatCommand(esHome, logger, "install", installStatusCallback);
    }

    public void Start(string esHome, IActivityLog logger)
    {
        Action startStatusCallback = () =>
        {
            if (!WindowsServiceManagement.IsServiceRunning(ComputerInfo.MachineName, ElasticsearchConstants.ElasticsearchServiceName))
            {
                logger.Info($"Waiting for Elasticsearch operation to complete...");
                throw new ElasticsearchOperationTimedoutException($"Elasticsearch operation was timedout.");
            }
        };
        InvokeServiceBatCommand(esHome, logger, "start", startStatusCallback);
    }

    private void InvokeServiceBatCommand(string esHome, IActivityLog logger, string command, Action statusCallback)
    {
        string commandString = command.ToLowerInvariant();
        Action elasticsearchConfigAction = () =>
        {
            ProcessStartInfo processInfo = new ProcessStartInfo
            {
                FileName = "cmd.exe",
                Arguments = $"/c elasticsearch-service.bat {commandString}",
                WorkingDirectory = Path.Combine(esHome, "bin"),
                UseShellExecute = false
            };

            string javaHome = Environment.GetEnvironmentVariable("JAVA_HOME", EnvironmentVariableTarget.Machine);
            Debug.Assert(!string.IsNullOrEmpty(javaHome));
            logger.Info($"Adding JAVA_HOME to the environment of child process, value: {javaHome}");
            processInfo.Environment["JAVA_HOME"] = javaHome;

            Task<MSVSCfg.ProcessOutput> task = ProcessHandler.RunExeAsync(processInfo, $"elasticsearch-service.bat {commandString}", logger, 
                default(CancellationToken));
            var timeout = TimeSpan.FromMilliseconds(ElasticsearchConstants.EsOperationTimeInMillsecs);

            if (Task.WaitAll(new[] { task }, timeout))
            {
                statusCallback();
            }
            else if (!task.IsCompleted)
            {
                throw new ElasticsearchOperationTimedoutException($"Elasticsearch operation: {command} was timedout.");
            }
        };

        RetryManager retryManager = new RetryManager(ElasticsearchConstants.EsOperationRetryCount, 
            TimeSpan.FromMilliseconds(300000), (ex) => logger.Warning(ex));
        retryManager.Invoke(elasticsearchConfigAction);
    }

```

In this particular scenario, JAVA\_HOME is set even before we start the ES install (we install JAVA at that location at the start of the application). If we retry the setup a second time, it works. So, the JAVA installation (in the previous retry) is also correct.

 ![SystemEnvVar2](https://us1.discourse-cdn.com/elastic/original/3X/c/5/c5b3fe99ea7303075d0a3136bc918dea59aa17d2.png)

Error logs:  
logs\elasticsearch-service-x64.\*.log

 ![ErrorLog](https://us1.discourse-cdn.com/elastic/original/3X/e/e/eedf2dcb0aa63a7b2a994ccdc75b62d4df2fab6e.PNG)

logs\elasticsearch-service-x64-stderr.\*.log

 ![ErrorLog2](https://us1.discourse-cdn.com/elastic/original/3X/6/c/6cbec332710ab07de9d9c8564bae34104e96435e.PNG)

 ![StdOut](https://us1.discourse-cdn.com/elastic/original/3X/a/3/a31ba21831b5be3c719cc5619ad54d412f83ad27.png)

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [December 29, 2017, 10:04am UTC](https://discuss.elastic.co/t/elasticsearch-service-fails-to-start/113470/4 "2017-12-29T10:04:27Z")

</div>

> [@ShilpiRachna](#):
>
> The data area passed to a system call is too small

I did a round of google and found this thread [Failed to start elasticsearch service · Issue #24187 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/24187) where they state that the memory setting might be incorrect. Specificly this might be helpfull [Failed to start elasticsearch service · Issue #24187 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/24187#issuecomment-295821224)

I cannot give you anymore info on this as I am not a windows user or admin.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 26, 2018, 10:04am UTC](https://discuss.elastic.co/t/elasticsearch-service-fails-to-start/113470/5 "2018-01-26T10:04:33Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
