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.

3

1 Answer 1

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.

5
  • Thanks Jan, When i executed ps -aux | grep 'elastic' | grep 'java' | awk -F " " '{ print $2 }' i dont get any result. root@baldelas01:/opt# ps -aux | grep 'elastic' | grep 'java' | awk -F " " '{ print $2 }' root@baldelas01:/opt# . So i tried removing "-" and used ps aux | grep 'elastic' | grep 'java' | awk -F " " '{ print $2 }' got the result. Thanks let me try this in script and see if it works. Mar 30, 2021 at 8:25
  • In the Script i tried stop) echo "Stopping $APP" processID="ps -ef | grep 'elastic' | grep 'java' | awk -F " " '{ print $2 }'" echo $processID sleep 30 kill $processID #/bin/su -m $USER -c "kill -9 (ps -ef | grep elastic) &> /dev/null" sleep 30 echo "$APP stopped successfully" However when i execute the restart file i get Stopping ElasticSearch ./elastic-auto-restart: 22: '{ print }': not found ;; Mar 30, 2021 at 8:37
  • Please ask that as a separate question because: pasting script in a comment makes in barely readable. you're telling us there's issue with line 22, but you're not pasting the full script. I can only see ~7 lines of it. then again I think you're still trying to kill something manually which already has a stop script in /etc/init.d/elasticsearch (hint: yes, it also contains a location of elasticsearch PID file, which contains process ID) Mar 30, 2021 at 9:59
  • Thanks i have created a seperate question as per the request with full script. askubuntu.com/questions/1334513/… Apr 28, 2021 at 8:10
  • Hi All, Please help May 10, 2021 at 5:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .