How To Run Elasticsearch Daemon Service

Have a Database Problem? Speak with an Expert for Free
Get Started >>

Introduction

A Daemon service is one that performs in the background without requiring the user to maintain direct control for it to execute. When Elasticsearch is installed, it can be set to perform certain actions by automation that is triggered by another event. The event could be a particular time and date, something like a file quota on an index, or any of a wide assortment of possibilities with this service. The steps that are laid out below will help explain just what needs to be done in order to take advantage of this capability and apply it as needed. This process can add a tremendous level of efficiency to the current system that may be in place for handling activities that consistently occur at regular intervals.

  • In order to get Elasticsearch to start each time that the server itself is rebooted, it will need to be added onto the server startup list.
  • Which operating system is running on the server of the reader is unknown. This article will be working with a Debian (Ubuntu) system, and for this configuration a user must make a file that can be placed into the directory /etc/init.d.
  • There is a copied file from a server below. It could already be on the OS. To find it, look for the file /etc/init.d/Elasticsearch
  • Then at this point, the Elasticsearch service wrapper is ready to go and can be tested by directly invoking the service like this:

/usr/local/share/Elasticsearch/bin/service/Elasticsearch

Usage: /usr/local/share/Elasticsearch/bin/service/Elasticsearch [ console | start | stop | restart | condrestart | status | install | remove | dump ]

Commands

console Launch in the current console.

start Start running the process as a daemon.

stop Stop if running as a daemon or in another console.

restart Stop if running and then start.

condrestart Restart only if already running.

status Query to find current status.

install Install and automatically start when system reboots.

remove Uninstall.

dump Requests Java thread dump when running.

  • So, that’s pretty cool, but next it is taken a bit further and shrinks how much will actually need to be typed. Edit the bash profile that looks like this ~/.bash_profile to add the code below:
1
2
3
4
5
6
7
8
9
10
11
12
13
alias es=Elasticsearch



Elasticsearch() {



/usr/local/share/Elasticsearch/bin/service/Elasticsearch $1



}

Prerequisites

  • Elasticsearch and JDK 8 need to already be installed on the machine or server intended to run the Elastic service.

Running Elasticsearch as a Daemon Service on Linux

  • After Elasticsearch and Oracle’s JDK is installed ,the service will not start as a default setting. The configuration is located in the /etc/sysconfig/Elasticsearch directory. A user can run these commands in terminal to enable Elasticsearch to start after the server or system has booted:
1
2
3
4
sudo update-rc.d Elasticsearch defaults 95 10


sudo /etc/init.d/Elasticsearch start
  • If a user is using an RPM-based Linux distribution (“Red Hat” distros like CentOS or Fedora) they will have to use chkconfig to enable and disable services. The init file for the Elasticsearch service is located in this directory:
1
/etc/init.d/Elasticsearch
  • To start the Elasticsearch services automatically after booting on RPM-based distros, a user just needs to enter the commands found below:
1
2
3
4
sudo /sbin/chkconfig --add Elasticsearch


sudo service Elasticsearch start
  • Conversely, if a user is running a SUSE Linux Enterprise Server they will have to use the systemd “System and Service Manager” instead to start or stop services.
  • SUSE distros using systemd to manage services have a utility called Systemctl that manages daemons, libraries, and utilities. A user can use these commands for enabling and starting the Elasticsearch service on this server distro:
1
2
3
4
5
6
7
sudo /bin/systemctl daemon-reload


sudo /bin/systemctl enable Elasticsearch.service


sudo /bin/systemctl start Elasticsearch.service

Running Elasticsearch as a Daemon Service on Windows

  • After Elasticsearch is installed on the Windows OS the ES daemon service can automatically be started by passing commands to the service.bat file. This file can be found in the c:\Elasticsearch-{VERSION}\bin folder. Here are the various commands:
1
2
3
4
5
6
7
8
9
10
11
12
13
service.bat install


service.bat remove


service.bat start


service.bat stop


service.bat manager

Conclusion

A lot of really useful tasks can be completed with ease when using the Elastic Stack of programs to designate and fully automate actions by creating them as Daemon services. This will add a whole new level of sophistication to the monitoring and analytics that go into keeping the operation running smoothly at every turn. This will free up more time for other things that need attention and have not yet been prioritized due to time constraints aggravated by inefficient methods. This walkthrough is filled with a lot of knowledge on how to make that happen with the Daemon service running scheduled system commands automatically without being prompted. This guide was made with the reader in mind, as are all the guides found here, which makes the idea of looking up another a highly recommended suggestion.

Pilot the ObjectRocket Platform Free!

Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.

Get Started

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.