# Restart the java application , first killing the process

**URL:** <https://forum.ansible.com/t/restart-the-java-application-first-killing-the-process/31126>\
**Category:** Ansible Project\
**Created:** [August 26, 2019, 1:53pm UTC](https://forum.ansible.com/t/restart-the-java-application-first-killing-the-process/31126 "2019-08-26T13:53:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ravi\_Ranjan](https://avatars.discourse-cdn.com/v4/letter/r/ecc23a/32.png) [@Ravi\_Ranjan](https://forum.ansible.com/u/Ravi_Ranjan)\
**Post date:** [August 26, 2019, 1:53pm UTC](https://forum.ansible.com/t/restart-the-java-application-first-killing-the-process/31126/1 "2019-08-26T13:53:40Z")

</div>

Hi Team ,

I am planning to do up gradation some app and for so we need to restart the java application once my other app is upgraded and for so , i have written a playbook.

can someone please help to write a play for starting the application . ( Start command i have grep from "ps -ef | grep java | grep newrelic )

[root@chnr1-book4flights4extapi-1 ~]# ps -ef | grep java | grep newrelic  
lmny+ 8328 1 0 Jul09 ? 06:10:13 **java -server -Xms1g -Xmx3g -d64 -Dnewrelic.config.distributed\_tracing.enabled=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -XX:+UseG1GC -Dct.ctconfig.consul.server=[http://consul-ctconfig.cltp.com:8500](http://consul-ctconfig.cltp.com:8500) -Dct.common.servertype=book4flights4extapi -Dapp.context.path=book -Dspring.profiles.active=prod,book4flights4extapi -javaagent:/opt/cal/newrelic/newrelic.jar -jar /opt/cal/latest.war**

**Note\*\* -** letter in bold letter is start command.

Command to start the application is :- **nohup** **java -server -Xms1g -Xmx3g -d64 -Dnewrelic.config.distributed\_tracing.enabled=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -XX:+UseG1GC -Dct.ctconfig.consul.server=[http://consul-ctconfig.cltp.com:8500](http://consul-ctconfig.cltp.com:8500) -Dct.common.servertype=book4flights4extapi -Dapp.context.path=book -Dspring.profiles.active=prod,book4flights4extapi -javaagent:/opt/cal/newrelic/newrelic.jar -jar /opt/cal/latest.war &**

**Playbook:**

**tasks:**  
**- name: Create a directory to take the backup of old new relic configuration**  
**file:**  
**path: /opt/cal/newrelic/newrelic\_old**  
**state: directory**  
**mode: ‘0755’**

**- name: To take the backup of all the existing new configuration of newrelic**  
**shell: “mv /opt/cal/newrelic/newrelic\* /opt/cal/newrelic/newrelic\_old/”**

**- name: " To update the new relic version of jar "**  
**copy:**  
**src: /home/raviranjan/newrelic/{{ item }}**  
**dest: /opt/cal/newrelic/**  
**with\_items:**  
**- newrelic.jar**  
**- newrelic.yml**

**- name: To get the running process for newrelic**  
**shell: "ps -ef | grep java | grep newrelic | awk ‘{print $2}’ | xargs kill -9 "**  
**register: running\_process**

**- name: To start the application**

any guidance would be much appreciated

---

<div class="post-metadata">

**Author:** ![dch](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dch/32/7132_2.png) [@dch](https://forum.ansible.com/u/dch)\
**Post date:** [August 29, 2019, 4:44am UTC](https://forum.ansible.com/t/restart-the-java-application-first-killing-the-process/31126/2 "2019-08-29T04:44:38Z")

</div>

You’re better off using your OS daemon functionality like systemd or rc.d script and letting the os handle all of this rather than trying to reinvent all of that in Ansible. Then you can use a notify to the service module in a handler.

Dave
