We have to start our elasticsearch manually every time our servers are rebooted due to security patching or other OS maintenance related so I'm looking for a script to start elasticsearch automatically after a server is rebooted. We are running RHEL 6.8. It looks like we have something shipped with 0.90 release but was no longer available after 2.4 release?? Can anyone share it please?
"RedHat based distributions are using chkconfig to enable and disable services. The init script is at /etc/init.d/elasticsearch, where as the configuration file is placed at /etc/sysconfig/elasticsearch"
Thanks anyway! I've just installed elasticsearch 5.4 on a new sever running REHL 7.3. I also found this doc
"Auto-starting Services with systemd" section
According to instructions in the above section, I need to have the init script for elasticsearch before I can run those commands that you gave right? It looks like 5.4 doesn't come with the script. I don't know how to write one. Can you or anyone else help please?
I did try the commands:
2) Ran daemon_reload
3) Systemctl enable elasticsearch FAILED
a. [root@dzbsdlr001 init.d]# systemctl enable elasticsearch
b. Failed to execute operation: No such file or directory
Looks like the service has not been implemented yet.
It looks like 5.4 doesn't come with a functional systemd init script located at /etc/systemd/system/multi-user.target.wants/service.service that's why the command failed:
[root@abzedlr001 init.d]# systemctl enable elasticsearch.service
Failed to execute operation: No such file or directory
How about your system? Where is it on your system?
On my system, that file is placed at /usr/lib/systemd/system/elasticsearch.service.
Its content:
[root@elkstack54 ~]# cat /usr/lib/systemd/system/elasticsearch.service
[Unit]
Description=Elasticsearch
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target
[Service]
Environment=ES_HOME=/usr/share/elasticsearch
Environment=CONF_DIR=/etc/elasticsearch
Environment=DATA_DIR=/var/lib/elasticsearch
Environment=LOG_DIR=/var/log/elasticsearch
Environment=PID_DIR=/var/run/elasticsearch
EnvironmentFile=-/etc/sysconfig/elasticsearch
WorkingDirectory=/usr/share/elasticsearch
User=elasticsearch
Group=elasticsearch
ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec
ExecStart=/usr/share/elasticsearch/bin/elasticsearch \
-p ${PID_DIR}/elasticsearch.pid \
--quiet \
-Edefault.path.logs=${LOG_DIR} \
-Edefault.path.data=${DATA_DIR} \
-Edefault.path.conf=${CONF_DIR}
# StandardOutput is configured to redirect to journalctl since
# some error messages may be logged in standard output before
# elasticsearch logging system is initialized. Elasticsearch
# stores its logs in /var/log/elasticsearch and does not use
# journalctl by default. If you also want to enable journalctl
# logging, you can simply remove the "quiet" option from ExecStart.
StandardOutput=journal
StandardError=inherit
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Specifies the maximum number of bytes of memory that may be locked into RAM
# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option
# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/sysconfig/elasticsearch
LimitMEMLOCK=infinity
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0
# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM
# Java process is never killed
SendSIGKILL=no
# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
# Built for distribution-5.4.0 (distribution)
Did you install elasticsearch with RPM? I installed elasticsearch from a tar file. Silly me but I wonder if elasticsearch.service only come with RPM package?
Yes, I downloaded RPM from official site an installed it. I didn't created file elasticsearch.service manually. It was autocreated when I executed systemctl commands mentioned above.
@hungl99 i too am using the binaries from the tar and running elasticsearch. please do update if you find a solution to run elasticsearch as a service.
Hi, I'm also having this problem because I wanted to install elasticsearch (and logstash and kibana) in /opt which is a filesystem I'd allocated extra space to for these tools.
I did the RPM install first which I then realised didn't install into /opt so I removed it and did the manual install but it is rather frustrating to find no init scripts.
I have the init script left over the from RPM install so I'm going to have a look at that and see if I can just change the paths in it to match mine, but if someone has a official one for elasticsearch 5.3.0 I'd be very grateful.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.