You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Doug Reeder <re...@gmail.com> on 2008/11/13 00:57:28 UTC

status from shell script (System V starup)

I've written a bash shell script to start and stop geronimo, for use  
with System V startup (scripts in /etc/rc.d/init.d/).

Start and stop are straightforward, as the scripts in $GERONIMO_HOME/ 
bin/ just need to be called, but status is less obvious.  The best  
I've come up with so far is

su -l -c "$GERONIMO_HOME/bin/deploy.sh -u $GERONIMO_ADMIN -p  
$GERONIMO_PASSWORD list-modules" $USER

but it's not satisfactory:
1) if geronimo is not running, it produces a stack dump, when all I  
want is a simple message indicating geronimo is not running

2) I have to include the geronimo administrator password in the  
script  (of course, it also needs to be in the script so geronimo can  
be shut down).

Can anyone suggest something better?   If geronimo is running, what  
would be best is a short list of all the ports it's listening on.   
(Then one could use netstat or whatever to see if one can actually  
access them).



RE: status from shell script (System V starup)

Posted by "Ghattu, Satya " <sa...@citi.com>.
You can ping the http(s) port to see if the server is up or down.

-----Original Message-----
From: Doug Reeder [mailto:reeder.29@gmail.com] 
Sent: Wednesday, November 12, 2008 6:57 PM
To: user@geronimo.apache.org
Subject: status from shell script (System V starup)

I've written a bash shell script to start and stop geronimo, for use  
with System V startup (scripts in /etc/rc.d/init.d/).

Start and stop are straightforward, as the scripts in $GERONIMO_HOME/ 
bin/ just need to be called, but status is less obvious.  The best  
I've come up with so far is

su -l -c "$GERONIMO_HOME/bin/deploy.sh -u $GERONIMO_ADMIN -p  
$GERONIMO_PASSWORD list-modules" $USER

but it's not satisfactory:
1) if geronimo is not running, it produces a stack dump, when all I  
want is a simple message indicating geronimo is not running

2) I have to include the geronimo administrator password in the  
script  (of course, it also needs to be in the script so geronimo can  
be shut down).

Can anyone suggest something better?   If geronimo is running, what  
would be best is a short list of all the ports it's listening on.   
(Then one could use netstat or whatever to see if one can actually  
access them).



Re: status from shell script (System V starup)

Posted by David Jencks <da...@yahoo.com>.
On Nov 12, 2008, at 3:57 PM, Doug Reeder wrote:

> I've written a bash shell script to start and stop geronimo, for use  
> with System V startup (scripts in /etc/rc.d/init.d/).
>
> Start and stop are straightforward, as the scripts in $GERONIMO_HOME/ 
> bin/ just need to be called, but status is less obvious.  The best  
> I've come up with so far is
>
> su -l -c "$GERONIMO_HOME/bin/deploy.sh -u $GERONIMO_ADMIN -p  
> $GERONIMO_PASSWORD list-modules" $USER
>
> but it's not satisfactory:
> 1) if geronimo is not running, it produces a stack dump, when all I  
> want is a simple message indicating geronimo is not running
>
> 2) I have to include the geronimo administrator password in the  
> script  (of course, it also needs to be in the script so geronimo  
> can be shut down).
>
> Can anyone suggest something better?   If geronimo is running, what  
> would be best is a short list of all the ports it's listening on.   
> (Then one could use netstat or whatever to see if one can actually  
> access them).

There are no guarantees any particular port will be in use.  The ports  
are generally set in var/config/config-substitutions.properties.  The  
port most likely to be open on any geronimo server is the jndi port,  
normally NamingPort + PortOffset or 1099 + 0.

I know nothing about this stuff but kinda thought usually one put the  
PID of the process in a file and if the PID was still there you  
figured the app was running..... like I said I know nothing.

thanks
david jencks

>
>
>


Re: status from shell script (System V starup)

Posted by Jack Cai <gr...@gmail.com>.
Doug, good job! I agree with Donald that we shall be thinking of reusing
this script. I'm currently working on turning Geronimo into a Windows
service. I think your script can be used to turn Geronimo into a service in
Unix-like systems.

- Jack

2008/11/20 Doug Reeder <re...@gmail.com>

> One certainly could write the script to return extensive status info, and
> the status command is not even required, but most System V init scripts
> return something like this for status:sshd (pid 8204 2405) is running...
> The scripts are mainly for starting and stopping daemons, and the status
> command appears to exist to let you know if you should run start or stop.
> Perhaps I should keep the list-modules code for an "info" command.
>
>
> On Wed, Nov 19, 2008 at 9:00 AM, Ted Kirby <te...@gmail.com> wrote:
>
>> I like the deploy.sh approach.  If you get a proper response, you have
>> more confidence the server is running well.  With the other approach,
>> the server process could be hung.  It is quick, tho.  If the deploy.sh
>> hangs, you'd have to account for that.
>>
>> On Wed, Nov 12, 2008 at 6:57 PM, Doug Reeder <re...@gmail.com> wrote:
>> > I've written a bash shell script to start and stop geronimo, for use
>> with
>> > System V startup (scripts in /etc/rc.d/init.d/).
>> >
>> > Start and stop are straightforward, as the scripts in
>> $GERONIMO_HOME/bin/
>> > just need to be called, but status is less obvious.  The best I've come
>> up
>> > with so far is
>> >
>> > su -l -c "$GERONIMO_HOME/bin/deploy.sh -u $GERONIMO_ADMIN -p
>> > $GERONIMO_PASSWORD list-modules" $USER
>> >
>> > but it's not satisfactory:
>> > 1) if geronimo is not running, it produces a stack dump, when all I want
>> is
>> > a simple message indicating geronimo is not running
>>
>> Wouldn't > /dev/null and/or 2>/dev/null handle that?
>>
>> > 2) I have to include the geronimo administrator password in the script
>>  (of
>> > course, it also needs to be in the script so geronimo can be shut down).
>>
>> You could use deploy --login:
>>
>> http://cwiki.apache.org/GMOxDOC22/tools-and-commands.html#Toolsandcommands-Login
>>
>> > Can anyone suggest something better?   If geronimo is running, what
>> would be
>> > best is a short list of all the ports it's listening on.  (Then one
>> could
>> > use netstat or whatever to see if one can actually access them).
>>
>> Ted Kirby
>>
>
>

Re: status from shell script (System V starup)

Posted by Doug Reeder <re...@gmail.com>.
One certainly could write the script to return extensive status info, and
the status command is not even required, but most System V init scripts
return something like this for status:sshd (pid 8204 2405) is running...
The scripts are mainly for starting and stopping daemons, and the status
command appears to exist to let you know if you should run start or stop.
Perhaps I should keep the list-modules code for an "info" command.


On Wed, Nov 19, 2008 at 9:00 AM, Ted Kirby <te...@gmail.com> wrote:

> I like the deploy.sh approach.  If you get a proper response, you have
> more confidence the server is running well.  With the other approach,
> the server process could be hung.  It is quick, tho.  If the deploy.sh
> hangs, you'd have to account for that.
>
> On Wed, Nov 12, 2008 at 6:57 PM, Doug Reeder <re...@gmail.com> wrote:
> > I've written a bash shell script to start and stop geronimo, for use with
> > System V startup (scripts in /etc/rc.d/init.d/).
> >
> > Start and stop are straightforward, as the scripts in $GERONIMO_HOME/bin/
> > just need to be called, but status is less obvious.  The best I've come
> up
> > with so far is
> >
> > su -l -c "$GERONIMO_HOME/bin/deploy.sh -u $GERONIMO_ADMIN -p
> > $GERONIMO_PASSWORD list-modules" $USER
> >
> > but it's not satisfactory:
> > 1) if geronimo is not running, it produces a stack dump, when all I want
> is
> > a simple message indicating geronimo is not running
>
> Wouldn't > /dev/null and/or 2>/dev/null handle that?
>
> > 2) I have to include the geronimo administrator password in the script
>  (of
> > course, it also needs to be in the script so geronimo can be shut down).
>
> You could use deploy --login:
>
> http://cwiki.apache.org/GMOxDOC22/tools-and-commands.html#Toolsandcommands-Login
>
> > Can anyone suggest something better?   If geronimo is running, what would
> be
> > best is a short list of all the ports it's listening on.  (Then one could
> > use netstat or whatever to see if one can actually access them).
>
> Ted Kirby
>

Re: status from shell script (System V starup)

Posted by Ted Kirby <te...@gmail.com>.
I like the deploy.sh approach.  If you get a proper response, you have
more confidence the server is running well.  With the other approach,
the server process could be hung.  It is quick, tho.  If the deploy.sh
hangs, you'd have to account for that.

On Wed, Nov 12, 2008 at 6:57 PM, Doug Reeder <re...@gmail.com> wrote:
> I've written a bash shell script to start and stop geronimo, for use with
> System V startup (scripts in /etc/rc.d/init.d/).
>
> Start and stop are straightforward, as the scripts in $GERONIMO_HOME/bin/
> just need to be called, but status is less obvious.  The best I've come up
> with so far is
>
> su -l -c "$GERONIMO_HOME/bin/deploy.sh -u $GERONIMO_ADMIN -p
> $GERONIMO_PASSWORD list-modules" $USER
>
> but it's not satisfactory:
> 1) if geronimo is not running, it produces a stack dump, when all I want is
> a simple message indicating geronimo is not running

Wouldn't > /dev/null and/or 2>/dev/null handle that?

> 2) I have to include the geronimo administrator password in the script  (of
> course, it also needs to be in the script so geronimo can be shut down).

You could use deploy --login:
http://cwiki.apache.org/GMOxDOC22/tools-and-commands.html#Toolsandcommands-Login

> Can anyone suggest something better?   If geronimo is running, what would be
> best is a short list of all the ports it's listening on.  (Then one could
> use netstat or whatever to see if one can actually access them).

Ted Kirby

Re: status from shell script (System V starup)

Posted by Donald Woods <dw...@apache.org>.
Doug, can you open a JIRA and attach your script as a patch/file with 
the ASF contribution flag checked, so we can possibly include this as a 
sample or in the server assemblies?

https://issues.apache.org/jira/browse/GERONIMO

Or reply to this thread with the statement that you "Grant license to 
ASF for inclusion in ASF works (as per the Apache License)" for your 
posted script.

Thanks.
-Donald


Doug Reeder wrote:
> Thanks for the suggestion -- I didn't want to have to modify the start 
> script to save the PID.  Here's what I've come up with -- it's not 
> polished, but does what you need a System V startup script to do:
> 
> #! /bin/sh
> ### BEGIN INIT INFO
> # Provides:          geronimo
> # Required-Start:    $local_fs $remote_fs
> # Required-Stop:     $local_fs $remote_fs
> # Default-Start:     2 3 4 5
> # Default-Stop:      S 0 1 6
> # Short-Description: Apache Geronimo application server
> # Description:       Apache Geronimo startup script
> ### END INIT INFO
> set -e
> 
> PATH=/sbin:/bin:/usr/sbin:/usr/bin
> #DESC="Apache Geronimo"
> NAME=geronimo
> USER=gdaemon
> JAVA_HOME=/usr/java/jdk
> GERONIMO_HOME=/usr/local/geronimo
> DAEMON=$GERONIMO_HOME/bin/geronimo.sh
> SCRIPTNAME=/etc/init.d/$NAME
> GERONIMO_ADMIN=gadmin
> GERONIMO_PASSWORD=xxxxxx
> 
> # JAVA_HOME must be set
> export JAVA_HOME
> 
> # Gracefully exit if the package has been removed.
> test -x $DAEMON || exit 0
> 
> #
> #       Function that starts the daemon/service.
> #
> d_start() {
>     su -c "$DAEMON start" $USER
> }
> 
> #
> #       Function that stops the daemon/service.
> #
> d_stop() {
>         su -c "$DAEMON stop --user $GERONIMO_ADMIN --password 
> $GERONIMO_PASSWORD" $USER
> }
> 
> #
> #        Function that gets status
> #
> d_status() {
>     ps_log=`mktemp /var/tmp/geronimo-ps$$.log`
>     ps auxww >"$ps_log"
>     if grep " -Dorg.apache.geronimo.base.dir=.*server.jar" "$ps_log" 
>  >/dev/null 2>/dev/null; then
>         echo "$NAME is running"
>     else
>         echo "$NAME is not running"
>     fi
>     rm -f "$ps_log"
> }
> 
> case "$1" in
>   start)
>         echo -n "Starting $NAME"
>         d_start
>         echo "."
>         ;;
>   stop)
>         echo  "Stopping $NAME"
>         d_stop
>         echo "."
>         ;;
>   restart)
>         #
>         #       If the "reload" option is implemented, move the 
> "force-reload"
>         #       option to the "reload" entry above. If not, 
> "force-reload" is
>         #       just the same as "restart".
>         #
>         echo  "Restarting $NAME"
>         d_stop
>         # One second might not be time enough for a daemon to stop,
>         # if this happens, d_start will fail (and dpkg will break if
>         # the package is being upgraded). Change the timeout if needed
>         # be, or change d_stop to have start-stop-daemon use --retry.
>         # Notice that using --retry slows down the shutdown process 
> somewhat.
>         sleep 10
>         d_start
>         echo "."
>         ;;
>   status)
>         d_status
>     echo "."
>     ;;
>   *)
>         echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
>         exit 3
>         ;;
> esac
> 
> exit 0
> 

Re: status from shell script (System V starup)

Posted by Doug Reeder <re...@gmail.com>.
Thanks for the suggestion -- I didn't want to have to modify the start  
script to save the PID.  Here's what I've come up with -- it's not  
polished, but does what you need a System V startup script to do:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          geronimo
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: Apache Geronimo application server
# Description:       Apache Geronimo startup script
### END INIT INFO
set -e

PATH=/sbin:/bin:/usr/sbin:/usr/bin
#DESC="Apache Geronimo"
NAME=geronimo
USER=gdaemon
JAVA_HOME=/usr/java/jdk
GERONIMO_HOME=/usr/local/geronimo
DAEMON=$GERONIMO_HOME/bin/geronimo.sh
SCRIPTNAME=/etc/init.d/$NAME
GERONIMO_ADMIN=gadmin
GERONIMO_PASSWORD=xxxxxx

# JAVA_HOME must be set
export JAVA_HOME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

#
#       Function that starts the daemon/service.
#
d_start() {
	su -c "$DAEMON start" $USER
}

#
#       Function that stops the daemon/service.
#
d_stop() {
         su -c "$DAEMON stop --user $GERONIMO_ADMIN --password  
$GERONIMO_PASSWORD" $USER
}

#
#        Function that gets status
#
d_status() {
     ps_log=`mktemp /var/tmp/geronimo-ps$$.log`
     ps auxww >"$ps_log"
     if grep " -Dorg.apache.geronimo.base.dir=.*server.jar" "$ps_log"  
 >/dev/null 2>/dev/null; then
         echo "$NAME is running"
     else
         echo "$NAME is not running"
     fi
     rm -f "$ps_log"
}

case "$1" in
   start)
         echo -n "Starting $NAME"
         d_start
         echo "."
         ;;
   stop)
         echo  "Stopping $NAME"
         d_stop
         echo "."
         ;;
   restart)
         #
         #       If the "reload" option is implemented, move the  
"force-reload"
         #       option to the "reload" entry above. If not, "force- 
reload" is
         #       just the same as "restart".
         #
         echo  "Restarting $NAME"
         d_stop
         # One second might not be time enough for a daemon to stop,
         # if this happens, d_start will fail (and dpkg will break if
         # the package is being upgraded). Change the timeout if needed
         # be, or change d_stop to have start-stop-daemon use --retry.
         # Notice that using --retry slows down the shutdown process  
somewhat.
         sleep 10
         d_start
         echo "."
         ;;
   status)
         d_status
	echo "."
	;;
   *)
         echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
         exit 3
         ;;
esac

exit 0


Re: status from shell script (System V starup)

Posted by Donald Woods <dw...@apache.org>.
Cool!  Maybe you'd like to open a JIRA and contribute your script once 
you're done?  :-)

For the status, maybe you could try something like -

isGeronimoRunning()
{
   ps_log=`mktemp /var/tmp/geronimo-ps.log`
   ps auxww >"$ps_log"
   geronimo_is_running="false"
   if grep " -Dorg.apache.geronimo.base.dir=.*server.jar" "$ps_log" 
 >/dev/null 2>/dev/null ; then
     geronimo_is_running="true"
   fi
   rm -f "$ps_log"
   test "$geronimo_is_running" = "true"
}



-Donald


Doug Reeder wrote:
> I've written a bash shell script to start and stop geronimo, for use 
> with System V startup (scripts in /etc/rc.d/init.d/).
> 
> Start and stop are straightforward, as the scripts in 
> $GERONIMO_HOME/bin/ just need to be called, but status is less obvious.  
> The best I've come up with so far is
> 
> su -l -c "$GERONIMO_HOME/bin/deploy.sh -u $GERONIMO_ADMIN -p 
> $GERONIMO_PASSWORD list-modules" $USER
> 
> but it's not satisfactory:
> 1) if geronimo is not running, it produces a stack dump, when all I want 
> is a simple message indicating geronimo is not running
> 
> 2) I have to include the geronimo administrator password in the script  
> (of course, it also needs to be in the script so geronimo can be shut 
> down).
> 
> Can anyone suggest something better?   If geronimo is running, what 
> would be best is a short list of all the ports it's listening on.  (Then 
> one could use netstat or whatever to see if one can actually access them).
> 
> 
>