Restart the java application , first killing the process

12 views
Skip to first unread message

Ravi Ranjan

unread,
Aug 26, 2019, 9:53:40 AM8/26/19
to Ansible Project
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 -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 -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 






Dave Cottlehuber

unread,
Aug 29, 2019, 12:45:11 AM8/29/19
to ansible...@googlegroups.com
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

On Mon, 26 Aug 2019, at 15:53, Ravi Ranjan wrote:
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 -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 -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 
*
*
*
*
*
*




-- 
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.


  Dave Cottlehuber
  +43 67 67 22 44 78
  Managing Director
  Skunkwerks, GmbH
  ATU70126204
  Firmenbuch 410811i


Reply all
Reply to author
Forward
0 new messages