0

We are trying to run a script to stop elasticsearch.

When I execute ps aux |grep elastic I am getting:

root@baldelas01:/tmp# ps aux |grep elastic
root     3016819  0.0  0.1   8248  4164 pts/2    S    14:43   0:00 su elasticsearch
elastic+ 3016820  0.0  0.1   7460  4260 pts/2    S+   14:43   0:00 bash
elastic+ 3016870  0.8 33.9 5562772 1369948 pts/2 Sl   14:43   0:37 /bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-3054796781310172182 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/opt/elasticsearch-6.6.1 -Des.path.conf=/opt/elasticsearch-6.6.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /opt/elasticsearch-6.6.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
elastic+ 3016887  0.0  0.1 121920  6900 pts/2    Sl   14:43   0:00 /opt/elasticsearch-6.6.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller
root     3019325  0.0  0.0   6432   736 pts/1    R+   15:54   0:00 grep --color=auto elastic
root@baldelas01:/tmp#

How do I get the PID : 3016870 in the script and execute kill -9?

I tried pidof but that does not give any result.

muru
  • 207,228

1 Answers1

0

the pidof doesn't give any result because elastcisearch is run through java binary.

the not-so-simple solution to get the id would be:

ps -aux | grep 'elastic' | grep 'java' | awk -F " " '{ print $2 }'

which is:

  • print all processes ( ps -aux )
  • filter the result by 'elastic' keyword ( grep 'elastic' )
  • filter the result by 'java' keyword ( grep 'java' )
  • only print second column ( awk -F " " '{ print $2 }' )

then you can kill specific ID using kill -9 if you really need to. However, please note it's always better to securely shut down the service by using the command suggested by Rinzwind in one of the comments.

Jan Myszkier
  • 1,273