简体   繁体   中英

Writing bash script for restarting JVMs

I have an application which is deployed on Linux environment and has two JVM's simultaneously running. One is producer and one is consumer.

I have different targets written in my ant script for stopping and starting the two JVMs.

There are times while restarting the producer or the consumer, one of the JVMs fail to stop so we have to go and manually find the process id for that particular port and kill that process and then start the application.

How could I automate this and write one script for everything. This script should be able to call the ant targets for stopping the JVMs, kill the process if any JVMs does not stop and finally start the two JVMs.

The first and the last is fine. But how to write things like finding the process id against the port and then doing kill -9.

I am a Java developer so don't know much about this.

If your JVMs are communicating on a socket then try something like

lsof | grep ":$port " | awk '{print $2}'

where $port is the port number. This searches the list of open file descriptors for any matching the required port number and spits out the process id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM