Elasticsearch 7.4.2 run as service in Linux environment

Hi,
I have installed elasticsearch 7.4.2 .zip in centos system but after running elasticsearch i got error in console which has mentioned below

Error in status :
elasticsearch-7.4.2.service - Elasticsearch-7.4.2
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch-7.4.2.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2020-01-02 05:04:31 EST; 8s ago
     Docs: http://www.elastic.co
  Process: 1894 ExecStart=/opt/elasticsearch-7.4.2/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet -Edefault.path.logs=${LOG_DIR} -Edefault.path.data=${DATA_DIR} -Edefault.path.conf=${CONF_DIR} (code=exited, status=1/FAILURE)
 Main PID: 1894 (code=exited, status=1/FAILURE)

systemd[1]: Started Elasticsearch-7.4.2.
systemd[1]: Starting Elasticsearch-7.4.2...
 systemd[1]: elasticsearch-7.4.2.service: main process exited, code=exited, status=1/FAILURE
 systemd[1]: Unit elasticsearch-7.4.2.service entered failed state.
 systemd[1]: elasticsearch-7.4.2.service failed.

I have created service file manually

[Unit]
Description=Elasticsearch-7.4.2
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target
[Service]
Environment=ES_HOME=/opt/elasticsearch-7.4.2
Environment=CONF_DIR=/opt/elasticsearch-7.4.2/config
Environment=DATA_DIR=/opt/elasticsearch-7.4.2/data
Environment=LOG_DIR=/opt/elasticsearch-7.4.2/logs
Environment=PID_DIR=/opt/elasticsearch-7.4.2
EnvironmentFile=-/opt/elasticsearch-7.4.2/elasticsearch-7.4.2

WorkingDirectory=/opt/elasticsearch-7.4.2

User=elasticsearch-7.4.2
Group=elasticsearch-7.4.2
#ExecStartPre=/opt/elasticsearch-7.4.2/bin/elasticsearch-systemd-pre-exec

ExecStart=/opt/elasticsearch-7.4.2/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 processes
LimitNPROC=2048

# Specifies the maximum size of virtual memory
LimitAS=infinity

# Specifies the maximum file size
LimitFSIZE=infinity

# Specifies the maximum file size
LimitFSIZE=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0

# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM

# Send the signal only to the JVM rather than its control group
KillMode=process

# 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 packages-7.4.2 (packages)

Could you please suggest me how to resolve this issue.

Can you post the relevant parts from the actual logs from within /var/log/elasticsearch/? Anything related to start-up, errors and shutdown.

Try installing .rpm package on centos.
and install latest jdk before installing rpm package.

hi,
thanks for replying .
Actually for rpm file it is working fine , i am trying to run elasticsearch from single place if you check my elasticsearch.service file you can see all are in same location but i know if i install from rpm it will start and will store in different location.

I am just want to run elasticsearch from elasticsearch.zip file and i have created my service file but it is failed to start i dont know why same process i have done in last 5.6.3 version it was working properly for this version it is not working .

I would like to request to check my service file once again which i have mentioned below and suggest me how to fix this issue it will great help for me

[Unit]
Description=elasticsearch-7.4.2
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target

[Service]
RuntimeDirectory=elasticsearch-7.4.2
Environment=ES_HOME=/opt/elasticsearch-7.4.2
Environment=ES_PATH_CONF=/opt/elasticsearch-7.4.2/config
Environment=PID_DIR=/opt/elasticsearch-7.4.2
EnvironmentFile=-/opt/elasticsearch-7.4.2/elasticsearch-7.4.2

User=elasticsearch-7.4.2
Group=elasticsearch-7.4.2

WorkingDirectory=/opt/elasticsearch-7.4.2

ExecStart=/opt/elasticsearch-7.4.2/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet

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 processes

LimitNPROC=4096

Specifies the maximum size of virtual memory

LimitAS=infinity

Disable timeout logic and wait until process is stopped

TimeoutStopSec=0

SIGTERM signal is used to stop the Java process

KillSignal=SIGTERM

Send the signal only to the JVM rather than its control group

KillMode=process

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-7.4.2 (distribution)

Hi Thanks for replying.
Yes for rpm file it is working fine. I am using JDK 11

Please find the below reply where i have mentioned service file of elastic search which i am using

Hi ,

Today i got the below error
Exception
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) [elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.main(Command.java:90) [elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) [elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) [elasticsearch-7.4.2.jar:7.4.2]
[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) ~[elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.4.2.jar:7.4.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.4.2.jar:7.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.4.2.jar:7.4.2]
... 6 more

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