57

How can I install Elastic Kibana (which is just a batch file) as a windows service?

It probably needs to depend on the ElasticSearch process as well (this assumes I'm running it on the same server)

jhilden
  • 12,207
  • 5
  • 53
  • 76

4 Answers4

72

The following command will create the service with a name of "ElasticSearch Kibana 4.0.1" and make it depend on ElasticSearch so it doesn't try to start too soon.

sc create "ElasticSearch Kibana 4.0.1" binPath= "{path to batch file}" depend= "elasticsearch-service-x64" 
jhilden
  • 12,207
  • 5
  • 53
  • 76
  • 9
    Please note that there should be a single whitespace after **binpath=** - it is required by sc utility cmd line format. Without whitespace, command is not valid and service is not created. – Alexander May 25 '15 at 10:21
  • 3
    @Alexander the same is true for the "depend" parameter (and any other params you want to pass to sc.exe). They need to be formatted like [paramName]= "param value". – Greg M. Jun 24 '15 at 15:25
  • For some reason I couldn't just type the command in powershell. I had to first save as a `.bat` file and then execute. – styfle Sep 29 '15 at 02:59
  • 7
    If you're running in Powershell, replace "sc" with "sc.exe", i.e. sc.exe create ... (because sc is, by default, an alias for set-content in Powershell) – Mark Nov 17 '15 at 16:49
  • 6
    I've got a service now installed but it does not start. Any way to troubleshoot this issue? – Muhammad Rehan Saeed Dec 03 '15 at 11:32
  • 24
    I have the same problem - kibana starts and runs, but the service gives an error and is marked as 'not running' even though kibana is still running in the background. – samjudson Jan 05 '16 at 22:41
  • 1
    I got this working using NSSM (None-Sucking-Service-Manager!) – samjudson Feb 09 '16 at 10:24
  • 2
    Did anybody figured out how to get service status to display correctly? – 4308 Nov 03 '16 at 14:48
  • `sc` did not work for me with Kibana 5.3.0, it started Kibana (node) but wasn't displaying it as started, I used `nssm` instead, see other answer. – stoft Apr 13 '17 at 11:35
  • 1
    Same here, installing via sc causes the process to be started but the service indicates an error when starting, i use nssm as described below. – Harry Jan 31 '20 at 10:13
  • SC is mean to be used with executables that support start and stop signals. So start a batch file as a service will fail in many situations, like a long warm up time or stopping the service. Using nssm tool to wrap the control of the batch file is a much better option. – MiguelSlv Aug 18 '23 at 10:25
50

The kibana.bat file delivered with Kibana 4.6.1 was not suited to use with sc create directly for me (Service start failed). I used nssm like this

  1. nssm install kibana461
  2. UI: choose kibana.bat as Application Path
  3. UI: select a log file to write to on "I/O" tab for stdout and stderr
  4. UI: on the "Dependencies" tab enter elasticsearch241 (or whatever you called it)
  5. UI: "Install Service"
  6. sc start kibana461
MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59
Christian
  • 13,285
  • 2
  • 32
  • 49
14

Rather than creating a dependency, I made a delayed start.

  1. First use the sc command (from jhilden).

    sc create "Elasticsearch Kibana 4.4.2" binPath= "C:\kibana-4.4.2-windows\bin\kibana.bat"
    
  2. Open services.msc and find your new service.

  3. Right click the service and select Properties.
  4. Change to Automatic (Delayed Start).
  5. If you haven't already, change Elasticsearch to Automatic.

services

This will ensure elasticsearch will start when the machine starts, and kibana will start sometime soon after (approx 2 minutes from this question).

Community
  • 1
  • 1
styfle
  • 22,361
  • 27
  • 86
  • 128
  • 1
    What advantage does this have over the dependency? – Henry Ing-Simmons Jul 15 '16 at 09:24
  • 1
    I linked to a related question in my answer. The relevant part: "Services set to Automatic will start during the boot process, while services set to start as Delayed will start shortly after boot." In my case, I want Elasticsearch to be up as soon as the server comes up and dedicate all resources to it, then we can start Kibana and dedicate resources after boot. – styfle Jul 15 '16 at 15:47
  • I am following this approach for Kibana 7.6.2 but I get this error message: "Error 1053: The service did not respond to the start or control request in a timely fashion" Any ideas? – Annie Sep 16 '20 at 22:06
9

I found this video very helpful.

Use NSSM (Non-sucking Service Manager) to install Kibana as a Service.

https://www.youtube.com/watch?v=L-0A2cqTn-w

Murali Bala
  • 1,133
  • 2
  • 18
  • 28