Everyone doing CI using an application server knows the problem: After some time you get OutOfMemoryError because of the excessive deployments.
The solution for this is to restart the application server periodically. But before you can start the application server, you must be sure to shut the application server down. This can be done for the weblogic with the stopWebLogic.sh script.
But what happens if the application server is already out of memory or has an other problem and is not going to shut down? This can be solved by killing the process on OS level.
Because I don’t want to kill the process always, I have written a script to first shutdown the server gracefully and if it doesn’t work, to kill the process. The script is executed from hudson remotely by a cron rule.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;"> 1</span> <span style="color: #000000;">#!/bin/bash </span><span style="color: #008080;"> 2</span> <span style="color: #000000;"> </span><span style="color: #008080;"> 3</span> <span style="color: #000000;"># Hudson doesn't start a login shell</span><span style="color: #000000;">,</span><span style="color: #000000;"> that's why we need to set some environment Variables </span><span style="color: #008080;"> 4</span> <span style="color: #000000;">HOSTNAME</span><span style="color: #000000;">=</span><span style="color: #000000;">my-weblogic-server.opitz-consulting.com </span><span style="color: #008080;"> 5</span> <span style="color: #000000;">export HOSTNAME </span><span style="color: #008080;"> 6</span> <span style="color: #000000;">env </span><span style="color: #008080;"> 7</span> <span style="color: #000000;"> </span><span style="color: #008080;"> 8</span> <span style="color: #000000;">DOMAIN_NAME</span><span style="color: #000000;">=</span><span style="color: #000000;">base_domain </span><span style="color: #008080;"> 9</span> <span style="color: #000000;">DOMAIN_HOME</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">/u01/app/oracle/middleware/user_projects/domains/${DOMAIN_NAME}</span><span style="color: #000000;">"</span><span style="color: #000000;"> </span><span style="color: #008080;">10</span> <span style="color: #000000;"> </span><span style="color: #008080;">11</span> <span style="color: #000000;">echo Trying to stop CI for </span><span style="color: #000000;">60</span><span style="color: #000000;"> seconds ... </span><span style="color: #008080;">12</span> <span style="color: #000000;"> </span><span style="color: #008080;">13</span> <span style="color: #000000;">cd ${DOMAIN_HOME} </span><span style="color: #008080;">14</span> <span style="color: #000000;">( ${DOMAIN_HOME}/bin/stopWebLogic.sh ) & sleep </span><span style="color: #000000;">60</span><span style="color: #000000;"> </span><span style="color: #008000;">;</span><span style="color: #008000;"> kill $!</span><span style="color: #008000;"> </span><span style="color: #008080;">15</span> <span style="color: #008000;"></span><span style="color: #000000;"> </span><span style="color: #008080;">16</span> <span style="color: #000000;">echo Killing CI if not stopped now ... </span><span style="color: #008080;">17</span> <span style="color: #000000;"> </span><span style="color: #008080;">18</span> <span style="color: #000000;">pkill -f ${DOMAIN_NAME} </span><span style="color: #008080;">19</span> <span style="color: #000000;"> </span><span style="color: #008080;">20</span> <span style="color: #000000;">echo Waiting </span><span style="color: #000000;">30</span><span style="color: #000000;"> seconds ... </span><span style="color: #008080;">21</span> <span style="color: #000000;"> </span><span style="color: #008080;">22</span> <span style="color: #000000;">sleep </span><span style="color: #000000;">30</span><span style="color: #000000;"> </span><span style="color: #008080;">23</span> <span style="color: #000000;"> </span><span style="color: #008080;">24</span> <span style="color: #000000;">rm nohup.out </span><span style="color: #008080;">25</span> <span style="color: #000000;"> </span><span style="color: #008080;">26</span> <span style="color: #000000;">echo Starting CI ... </span><span style="color: #008080;">27</span> <span style="color: #000000;"> </span><span style="color: #008080;">28</span> <span style="color: #000000;">nohup ${DOMAIN_HOME}/bin/startWebLogic.sh </span><span style="color: #000000;">2</span><span style="color: #000000;">>&</span><span style="color: #000000;">1</span><span style="color: #000000;"> & </span><span style="color: #008080;">29</span> <span style="color: #000000;"> </span><span style="color: #008080;">30</span> <span style="color: #000000;">echo Waiting </span><span style="color: #000000;">3</span><span style="color: #000000;"> minutes ... </span><span style="color: #008080;">31</span> <span style="color: #000000;"> </span><span style="color: #008080;">32</span> <span style="color: #000000;">sleep </span><span style="color: #000000;">180</span><span style="color: #000000;"> </span><span style="color: #008080;">33</span> <span style="color: #000000;"> </span><span style="color: #008080;">34</span> <span style="color: #000000;">tail nohup.out </span><span style="color: #008080;">35</span> <span style="color: #000000;"> </span><span style="color: #008080;">36</span> <span style="color: #000000;">echo Finished! </span><span style="color: #008080;">37</span> <span style="color: #000000;"></span></div> |
The script additionally appends the last lines of the server output after the restart to the log of the hudson job.
Bernhard Mähr @ OPITZ-CONSULTING published at http://thecattlecrew.wordpress.com/