LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-25-2005, 03:11 PM   #1
maringat
LQ Newbie
 
Registered: Jul 2005
Location: California
Distribution: SUSE, Red Hat
Posts: 3

Rep: Reputation: 0
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?
 
Old 07-25-2005, 03:51 PM   #2
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
Well, have you tried backgrounding the process?

Code:
<script blaablaa>
jboss &
<script continues>
 
Old 07-25-2005, 04:17 PM   #3
maringat
LQ Newbie
 
Registered: Jul 2005
Location: California
Distribution: SUSE, Red Hat
Posts: 3

Original Poster
Rep: Reputation: 0
Yes, that's exactly what the script does.
 
Old 07-25-2005, 04:26 PM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,768

Rep: Reputation: 307Reputation: 307Reputation: 307Reputation: 307
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.  

 Works but full timeout period is always waited before exiting  

  TIMEOUT=60  # timelimit for command 
   command_which_can_hang &    
    sleep $TIMEOUT;
This should allow time for JBoss to start in background, then return control to the terminal that started the script.
 
Old 07-25-2005, 05:03 PM   #5
maringat
LQ Newbie
 
Registered: Jul 2005
Location: California
Distribution: SUSE, Red Hat
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
Old 07-25-2005, 05:12 PM   #6
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
^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.. (;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
shell script problem. chooi Programming 7 03-26-2005 05:16 PM
Problem in shell script Kumar Programming 4 04-27-2004 08:48 AM
shell script problem steltner Linux - General 19 05-18-2003 02:42 PM
shell script problem steltner Programming 0 05-17-2003 03:26 PM


All times are GMT -5. The time now is 09:26 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration