# Elasticsearch 7.4.2 run as service in Linux environment

**URL:** <https://discuss.elastic.co/t/elasticsearch-7-4-2-run-as-service-in-linux-environment/213552>\
**Category:** Elasticsearch\
**Created:** [January 2, 2020, 10:17am UTC](https://discuss.elastic.co/t/elasticsearch-7-4-2-run-as-service-in-linux-environment/213552 "2020-01-02T10:17:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishek1989](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@abhishek1989](https://discuss.elastic.co/u/abhishek1989)\
**Post date:** [January 2, 2020, 10:17am UTC](https://discuss.elastic.co/t/elasticsearch-7-4-2-run-as-service-in-linux-environment/213552/1 "2020-01-02T10:17:26Z")

</div>

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

```auto
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

```auto
[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.

---

<div class="post-metadata">

**Author:** ![Emanuil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emanuil/32/36783_2.png) [@Emanuil](https://discuss.elastic.co/u/Emanuil)\
**Post date:** [January 4, 2020, 1:48am UTC](https://discuss.elastic.co/t/elasticsearch-7-4-2-run-as-service-in-linux-environment/213552/2 "2020-01-04T01:48:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mancharagopan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mancharagopan/32/60266_2.png) [@mancharagopan](https://discuss.elastic.co/u/mancharagopan)\
**Post date:** [January 4, 2020, 3:12am UTC](https://discuss.elastic.co/t/elasticsearch-7-4-2-run-as-service-in-linux-environment/213552/3 "2020-01-04T03:12:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![abhishek1989](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@abhishek1989](https://discuss.elastic.co/u/abhishek1989)\
**Post date:** [January 6, 2020, 5:32am UTC](https://discuss.elastic.co/t/elasticsearch-7-4-2-run-as-service-in-linux-environment/213552/4 "2020-01-06T05:32:05Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![abhishek1989](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@abhishek1989](https://discuss.elastic.co/u/abhishek1989)\
**Post date:** [January 6, 2020, 5:33am UTC](https://discuss.elastic.co/t/elasticsearch-7-4-2-run-as-service-in-linux-environment/213552/5 "2020-01-06T05:33:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![abhishek1989](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@abhishek1989](https://discuss.elastic.co/u/abhishek1989)\
**Post date:** [January 6, 2020, 9:58am UTC](https://discuss.elastic.co/t/elasticsearch-7-4-2-run-as-service-in-linux-environment/213552/6 "2020-01-06T09:58:58Z")

</div>

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

---

<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:** [February 3, 2020, 9:59am UTC](https://discuss.elastic.co/t/elasticsearch-7-4-2-run-as-service-in-linux-environment/213552/7 "2020-02-03T09:59:07Z")

</div>

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