Questo è come mi sto riavvio di Tomcat dopo la distribuzione via Jenkins.
Sto avendo due server DEV e QA in cui ho bisogno di fare la distribuzione e riavviare tomcat. Ho installato Jenkins nel server DEV.
- Per prima cosa è necessario installare Post build task Plugin in Jenkins.
- Poi creare questo script
tomcat-restart.ksh
nel server in cui è stato installato Tomcat ..
#!/bin/bash echo "*********************Restarting Tomcat70.******************" sh /apps/apache/sss-tomcat70.ksh status echo "Trying to stop Tomcat." sh /apps/apache/sss-tomcat70.ksh stop echo "Getting Tomcat Status." sh /apps/apache/sss-tomcat70.ksh status echo "Trying to Start Tomcat" sh /apps/apache/sss-tomcat70.ksh start sleep 2 echo "Getting Tomcat Status" sh /apps/apache/sss-tomcat70.ksh status
riavvio di Tomcat sul server di DEV.
Poiché Jenkins e Tomcat sono installati nello stesso computer, sto chiamando direttamente lo script.
In Jenkins andare a Add post-build action
e scegliere Post build task
e nel Script
testo aggiungere il seguente: /apps/apache/tomcat-restart.ksh
riavvio di Tomcat nel server di QA.
Poiché Jenkins è installato in un server diverso, sto richiamando lo script per riavviare Tomcat tramite Secure Shell.
In Jenkins vai a Aggiungere post-build action
selezionare Post build task
e nella casella di testo Script aggiungere il seguente:
sshpass -p 'myPassword' ssh -tt [email protected] sudo sh /apps/apache/tomcat-restart.ksh
È necessario installare sshpass
se non è già installato.
Se tutto è andato bene, allora potresti vedere qualcosa di simile nel tuo log di Jenkins.
Running script : /apps/apache/tomcat-restart.ksh
[workspace] $ /bin/sh -xe /tmp/hudson43653169595828207.sh
+ /apps/apache/tomcat-restart.ksh
*********************Restarting Tomcat70.*********************
Tomcat v7.0 is running as process ID 3552
*********************Trying to stop Tomcat.*********************
Stopping Tomcat v7.0 running as process ID 3552...
*********************Getting Tomcat Status.*********************
Tomcat v7.0 is not running
*********************Trying to Start Tomcat*********************
Starting Tomcat v7.0 server...
*********************Getting Tomcat Status*********************
Tomcat v7.0 is running as process ID 17969
Spero che questo aiuti.
Quando si esegue lo script batch? Se lo fai dopo "Eventi post-build", dovrebbe funzionare. – Akhil