Shell script problem
I've written some Bash scripts to deploy files from one server to another. The script on server A simply copies the files (using sftp) and then logs onto server B (using ssh) and executes a second script on server B. The second script merely restarts two services, namely Tomcat and JBoss. It has to start JBoss in the background, because the process has to continue after the script ends. Everything works correctly, except that when JBoss finishes booting up, the script appears to hang. I have to manually enter control-c on the keyboard before it returns and continues executing the script on server A. I'd like for the procedure to be totally automated.
Has anyone else encoutered this problem and fixed it? |
Well, have you tried backgrounding the process?
Code:
<script blaablaa> |
Yes, that's exactly what the script does.
|
It's an interesting problem. But, without seeing the lines of code which start JBoss, it's difficult to guess what the problem might be.
Can you show those few lines of code without compromising your system? Does the command which starts JBoss end with an ampersand (&) to tell bash to runn the process in background and return control to the script (terminal) which called it? You could also try inserting a timeout to see if that helps. I found this in a set of shell hints and tips I found somewhere on the web (author unknown to me). Code:
Command timeout (or aborting a command which can hang) This solution runs the command in the background and waits for it to complete. A sleep command is also run to provide a timeout. |
Here is the complete script that gets executed on server B:
#!/bin/bash # redeploy for live system export JAVA_HOME=/usr/java/j2sdk1.4.2_03 JBOSSDIR=/usr/local/jbosslive TOMCATDIR=/usr/local/tomcatlive STARTDIR=~/deploy cd $STARTDIR # redeploy tomcat if [ -a websrc.war ]; then # cycle live server cd $TOMCATDIR bin/shutdown.sh rm -rf $TOMCATDIR/webapps/websrc cp $STARTDIR/websrc.war $TOMCATDIR/webapps cd $TOMCATDIR/webapps mkdir websrc cd websrc jar xf ../websrc.war cd $TOMCATDIR bin/startup.sh fi # redeploy jboss # if app ear file present, kill existing process: cd $STARTDIR if [ -a app.ear ]; then # cycle live kill `ps -aexw | grep java | grep jbosslive | awk '{print $1}'` sleep 5 rm -rf $JBOSSDIR/server/default/work/* cp --reply=yes $STARTDIR/st.ear $JBOSSDIR/server/default/deploy cd $JBOSSDIR bin/run.sh & fi I can see from the output of the terminal session that JBoss completes its initialization, but the only way to get the script to continue is to press control-c. |
^C will just kill the task in the foreground.. So I realy doubt thats something you want?
Is there no built-in daemonize feature in jboss? I knew java stuff was weird, but id still think even java daemons have daemon modes.. (; |
All times are GMT -5. The time now is 03:20 AM. |