1825801 Members
2322 Online
109687 Solutions
New Discussion

Re: Script

 
Hunki
Super Advisor

Script

Can somebody suggest whats wrong with this script :


#! /bin/sh

start()
{
echo "Starting jboss.."
sudo -u com /home/tmp/cm/jboss-4.0.4.GA/bin/run.sh > /dev/null 2> /dev/null &
}

stop()
{
echo "Stopping jboss.."
sudo -u com /home/tmp/cm/jboss-4.0.4.GA/bin/shutdown.sh -S &
}

restart()
{
stop

# give stuff some time to stop before we restart
sleep 60

# protect against any services that can't stop before we restart (warning this kills all Java instances running as 'com' user)
sudo -u com /usr/sbin/killall java

start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: jboss {start|stop|restart}"
exit 1
esac

exit 0
9 REPLIES 9
Patrick Wallek
Honored Contributor

Re: Script

Are you getting errors when you run it? More details of what it is, or isn't doing, would be helpful.

Geoff Wild
Honored Contributor

Re: Script

Errors would be nice...

First off, you have a space between #! and /bin/sh

Try adding a set -x on second line and re running it.

I would add ' ' around the function names:

'start'()
{

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Raj D.
Honored Contributor

Re: Script

Hunki ,

What error are u getting ,
You can execute the script with -x option and hopefully you can debug the problem.


Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Hemmetter
Esteemed Contributor

Re: Script

Hi Hunki,

be careful about the sematic of the killall-command. It IS different to the LINUX-Killall.

SEE killall(1M):
DESCRIPTION
killall is a procedure used by /usr/sbin/shutdown to kill all active processes not directly related to the shutdown procedure.

rgds
HGH

Peter Godron
Honored Contributor

Re: Script

Hi,
additionally to the above comments have you tried:
sudo -u com -c "/home/tmp/cm/jboss-4.0.4.GA/bin/run.sh > /dev/null 2> /dev/null &"

you may need the -c option and quotes to get the redirection and background to work.

Also, change the function name stop as it may be a semi-reserved word.
Hunki
Super Advisor

Re: Script

I made the change to the script, here is what I have :

set -x
#!/bin/sh

start()
{
echo "Starting jboss.."
sudo -u com "/export/home/tmp/cm/jboss-4.0.4.GA/bin/run.sh > /dev/null 2> /dev/null &"
}

stopjb()
{
echo "Stopping jboss.."
sudo -u com "/export/home/tmp/cm/jboss-4.0.4.GA/bin/shutdown.sh -S &"
}

restart()
{
stopjb

# give stuff some time to stop before we restart
sleep 60

# protect against any services that can't stop before we restart (warning this kills all Java instances running as 'com' user)
#sudo -u com /usr/sbin/killall java

start
}

case "$1" in
start)
start
;;
stopjb)
stopjb
;;
restart)
restart
;;
*)
echo "Usage: jboss {start|stopjb|restart}"
exit 1
esac

exit 0

---------------

Here is the output I am getting :


>>./jboss restart
+ restart
Stopping jboss..
sudo: /home/tmp/cm/jboss-4.0.4.GA/bin/shutdown.sh -S &: command not found


>>./jboss start
+ start
Starting jboss..
sudo: /home/tmp/cm/jboss-4.0.4.GA/bin/run.sh > /dev/null 2> /dev/null &: command not found
+ exit 0


>>./jboss stopjb
+ stopjb
Stopping jboss..
sudo: /home/tmp/cm/jboss-4.0.4.GA/bin/shutdown.sh -S &: command not found
+ exit 0
Patrick Wallek
Honored Contributor

Re: Script

You probably need to fully qualify the path to 'sudo'.

If sudo is in /usr/local/bin the do:

/usr/locall/bin/sudo -u com /home/tmp/cm/jboss-4.0.4.GA/bin/shutdown.sh -S &
Hunki
Super Advisor

Re: Script

Got this modified a little :

#!/bin/sh

start()
{
echo "Starting jboss.."
/usr/bin/su - com -c "/export/home/tmp/jboss-4.0.4.GA/bin/run.sh > /dev/null 2> /dev/null &"
}

stopjb()
{
echo "Stopping jboss.."
/usr/bin/su - aqgt -c "/export/home/tmp/jboss-4.0.4.GA/bin/shutdown.sh -S &"
}

restart()
{
stopjb

# give stuff some time to stop before we restart
sleep 60

# protect against any services that can't stop before we restart (warning this kills all Java instances running as 'com' user)
#/usr/bin/su - com -c "/usr/bin/kill java"

start
}

case "$1" in
start)
start
;;
stopjb)
stopjb
;;
restart)
restart
;;
*)
echo "Usage: jboss {start|stopjb|restart}"
exit 1
esac

exit 0

Need to make the kill work in the restart function. Is there a way out .Also does the script looks workable apart from that.

Thanks,
Sandman!
Honored Contributor

Re: Script

un-comment the killall command and it should work i.e. change
#/usr/bin/su - com -c "/usr/bin/kill java"
to
/usr/bin/su - com -c "/usr/bin/kill java"