List Info

Thread: Changing BRANCH_1_2_X/lenya.sh




Changing BRANCH_1_2_X/lenya.sh
user name
2007-12-11 18:28:40
On 12/11/07, Thorsten Scherler <thorstenapache.org> wrote:
> On Thu, 2007-11-29 at 12:08 +0000, solproviderapache.org wrote:
> > Author: solprovider
> > Date: Thu Nov 29 04:08:11 2007
> > New Revision: 599401
> >
> > URL: 
http://svn.apache.org/viewvc?rev=599401&view=rev
> > Log:
> > Fixed Bug 43748.  Replaced bash-specific code with
POSIX sh acceptable code.
> >
> > Modified:
> >     lenya/branches/BRANCH_1_2_X/lenya.sh
> > URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_1_2
_X/lenya.sh?rev=599401&r1=599400&r2=599401&view=
diff
> >
> > +++ lenya/branches/BRANCH_1_2_X/lenya.sh Thu Nov
29 04:08:11 2007
> >  # Set Lenya home to directory containing this
script
> > +LENYA_HOME=${0%/*}
>
> Can you explain this change?
>
> If I open a shell and type
> echo ${0%/*}
>
> I get
> bash
>
> I do not understand.
>
> salu2
> >  cd $LENYA_HOME
> >  LENYA_HOME=`pwd -P`
> Thorsten Scherler                                
thorsten.at.apache.org

The goal of my revision to lenya.sh is to make LENYA_HOME
independent
of an environment variable.  Before this change, running any
of these
files:
   /lenya-1.2.2/lenya.sh
   /lenya-1.2.5/lenya.sh
   /lenya-1.2.x/lenya.sh
will start the same instance of Lenya because the
environment variable
overrides the path of the command.  This is not intuitive. 
When I run
/lenya-1.2.5/lenya.sh, I expect to launch Lenya 1.2.5, not
Lenya
1.2.2.  More critical, running multiple instances of Lenya
is not
possible when the launch command always reverts to a single
instance.
Editing the lenya.sh of each instance to hardcode the
directory
violates every rule of computing.

In ash, bash, csh, ksh, and every shell except the original
1977 sh,
${0%/*}
will remove the last slash and anything after the last slash
from the command.

echo $0
returns
-bash
because echo is integral to bash so the "command"
is bash.  Test using
the following script.

FILE: test.sh
#!/bin/sh
echo "PWD= `pwd`"
LENYA_HOME=${0%/*}
echo "LH1=$LENYA_HOME"
cd $LENYA_HOME
LENYA_HOME=`pwd -P`
echo "LH2=$LENYA_HOME"

Using people.apache.org:
/x1$ home/solprovider/test.sh
PWD= /x1
LH1=home/solprovider
LH2=/x1/home/solprovider

In English,
1. Get the path used to reach the current executable.
2. Change directory using the result of #1.  This is
relative to the
current directory.  The current directory (PWD) is the
directory from
which the command is called.
3. Get the absolute current path.  This removes dots and
symbolic links.

This code works on every *nix except SunOS.  SunOS uses the
original
1977 shell, which did not have good string manipulation.  sh
and awk
were the two required programs for Unix.    String
manipulation
required using awk.

I am ready to rewrite this to use awk to work on SunOS.  I
am waiting
for access to zones so I can test the code.  I dislike
guessing what
might work and submitting code hoping not to break
anything.

Suggestions welcome.

solprovider

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribelenya.apache.org
For additional commands, e-mail: dev-helplenya.apache.org


Re: Changing BRANCH_1_2_X/lenya.sh
country flaguser name
Spain
2007-12-12 04:01:50
On Tue, 2007-12-11 at 19:28 -0500, solproviderapache.org wrote:
> ...
> 
> The goal of my revision to lenya.sh is to make
LENYA_HOME independent
> of an environment variable.  Before this change,
running any of these
> files:
>    /lenya-1.2.2/lenya.sh
>    /lenya-1.2.5/lenya.sh
>    /lenya-1.2.x/lenya.sh
> will start the same instance of Lenya because the
environment variable
> overrides the path of the command.  

Hmm, should not if you have not set LENYA_HOME in your
environment
variables before starting lenya. Otherwise it would not have
been
possible to have two different instance on zone running.

> This is not intuitive.  When I run
> /lenya-1.2.5/lenya.sh, I expect to launch Lenya 1.2.5,
not Lenya
> 1.2.2.  More critical, running multiple instances of
Lenya is not
> possible when the launch command always reverts to a
single instance.

see above.

We had before
if [ "$LENYA_HOME" = "" ] ; then 
 LENYA_HOME='.' 
fi

Meaning when you do not set "$LENYA_HOME" it is
the same as you intend 
with your commit.

> Editing the lenya.sh of each instance to hardcode the
directory
> violates every rule of computing.

Agree, but we have not done that before.

> 
> In ash, bash, csh, ksh, and every shell except the
original 1977 sh,
> ${0%/*}
> will remove the last slash and anything after the last
slash from the command.
> 
> echo $0
> returns
> -bash
> because echo is integral to bash so the
"command" is bash.  Test using
> the following script.
> 
> FILE: test.sh
> #!/bin/sh
> echo "PWD= `pwd`"
> LENYA_HOME=${0%/*}
> echo "LH1=$LENYA_HOME"
> cd $LENYA_HOME
> LENYA_HOME=`pwd -P`
> echo "LH2=$LENYA_HOME"
> 
> Using people.apache.org:
> /x1$ home/solprovider/test.sh
> PWD= /x1
> LH1=home/solprovider
> LH2=/x1/home/solprovider
> 
> In English,
> 1. Get the path used to reach the current executable.
> 2. Change directory using the result of #1.  This is
relative to the
> current directory.  The current directory (PWD) is the
directory from
> which the command is called.
> 3. Get the absolute current path.  This removes dots
and symbolic links.
> 
> This code works on every *nix except SunOS.  SunOS uses
the original
> 1977 shell, which did not have good string
manipulation.  sh and awk
> were the two required programs for Unix.    String
manipulation
> required using awk.

Thanks for this detail explanation (the interested reader
may refer to
http://issues.apache.org/bugzilla/show_bug.cgi?id=43748 for more
information).

> 
> I am ready to rewrite this to use awk to work on SunOS.
 I am waiting
> for access to zones so I can test the code.  I dislike
guessing what
> might work and submitting code hoping not to break
anything.
> 
> Suggestions welcome.


Thanks for tackling this.

However I am not really sure whether this change is needed.

> 
> solprovider
> 
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: dev-unsubscribelenya.apache.org
> For additional commands, e-mail: dev-helplenya.apache.org
> 
-- 
Thorsten Scherler                                
thorsten.at.apache.org
Open Source Java                      consulting, training
and solutions


------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribelenya.apache.org
For additional commands, e-mail: dev-helplenya.apache.org


Re: Changing BRANCH_1_2_X/lenya.sh
user name
2007-12-12 14:38:31
On 12/12/07, Thorsten Scherler
<thorsten.scherler.extjuntadeandalucia.es>
wrote:
> On Tue, 2007-12-11 at 19:28 -0500, solproviderapache.org wrote:
> > The goal of my revision to lenya.sh is to make
LENYA_HOME independent
> > of an environment variable.  Before this change,
running any of these
> > files:
> >    /lenya-1.2.2/lenya.sh
> >    /lenya-1.2.5/lenya.sh
> >    /lenya-1.2.x/lenya.sh
> > will start the same instance of Lenya because the
environment variable
> > overrides the path of the command.
>
> Hmm, should not if you have not set LENYA_HOME in your
environment
> variables before starting lenya. Otherwise it would not
have been
> possible to have two different instance on zone
running.

I still cannot analyze how zone works because I do not have
access.  I
expect each instance is called from its own directory using
something
like:
   cd /lenya1
   lenya.sh servlet
   cd /lenya2
   lenya.sh servlet

> > This is not intuitive.  When I run
> > /lenya-1.2.5/lenya.sh, I expect to launch Lenya
1.2.5, not Lenya
> > 1.2.2.  More critical, running multiple instances
of Lenya is not
> > possible when the launch command always reverts to
a single instance.
> see above.
>
> We had before
> if [ "$LENYA_HOME" = "" ] ; then
>  LENYA_HOME='.'
> fi

This code works for exactly one case -- lenya.sh must be
called from
the Lenya directory.  Startup scripts must change to the
Lenya
directory before calling the launch command, and may still
have
unexpected results if LENYA_HOME is set as an environment
variable.
To test, try to run Lenya from a different directory without
setting
LENYA_HOME:
   cd /x1/home/solprovider
   /lenya-1.2.5/lenya.sh servlet
Results:
   INFO: No such war file lenya.war or build directory!
because the build directory and lenya.war file are not found
in the
/x1/home/solprovider directory.

> Meaning when you do not set "$LENYA_HOME" it
is the same as you intend
> with your commit.

Not setting LENYA_HOME still requires changing the directory
before
calling lenya.sh.  I am unaware of another program that
requires
changing the directory before calling the launch command.

I am not the only person aware of and working on this issue.
 Trunk's
lenya.sh includes:
   if [ "$LENYA_HOME" = "" ] ; then
     LENYA_HOME='.'
     # TODO: Make it startable from any directory
     #LENYA_HOME=`dirname $0`
     #echo "LENYA_HOME: $LENYA_HOME"
   fi

Who tried using "dirname"?  That code cannot fix
the issue because
LENYA_HOME is not set to the absolute path.  Can we use this
code?

   cd `dirname $0`
   LENYA_HOME=`pwd -P`

Is the dirname program more generically available than the
percent
sign syntax for string manipulation?

For the record, the rest of my original commit added a
"stop" command
line option and automatically shut down the Lenya instance
from this
directory before launching a new instance.  Lenya 2.0 should
benefit
from that code.

solprovider

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribelenya.apache.org
For additional commands, e-mail: dev-helplenya.apache.org


Re: Changing BRANCH_1_2_X/lenya.sh
user name
2007-12-12 14:47:50
My apologies.  Just found access to zones.  Changing
  /export/home/lenya/test
to test the new code.

Thank you,
solprovider

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribelenya.apache.org
For additional commands, e-mail: dev-helplenya.apache.org


Re: Changing BRANCH_1_2_X/lenya.sh
user name
2007-12-12 15:09:16
cd `dirname $0`
LENYA_HOME=`pwd -P`

This code works on zones.l.a.o (Solaris 2.10), people.a.o
(FreeBSD
6.2), and a Linux server.  I will commit this in the 1.2 and
1.3
branches.  Would somebody else please commit it in trunk?

solprovider

P.S. Here are the results on zones:

FILE: /export/home/lenya/test
#!/bin/sh
echo "PWD= `pwd`"
echo "CMD=$0"
LENYA_HOME=`dirname $0`
echo "DIR=$LENYA_HOME"
cd `dirname $0`
LENYA_HOME=`pwd -P`
echo "LH3=$LENYA_HOME"

$ cd /export/home/lenya
$ ./test
PWD= /export/home/lenya
CMD=./test
DIR=.
LH3=/export/home/lenya
$ cd /opt/local
$ /export/home/lenya/test
PWD= /opt/local
CMD=/export/home/lenya/test
DIR=/export/home/lenya
LH3=/export/home/lenya

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribelenya.apache.org
For additional commands, e-mail: dev-helplenya.apache.org


Re: Changing BRANCH_1_2_X/lenya.sh
country flaguser name
Spain
2007-12-12 16:10:08
Thanks for taking the time to explain the problem in more
detail.

On Wed, 2007-12-12 at 15:38 -0500, solproviderapache.org wrote:
...
> Who tried using "dirname"?  That code cannot
fix the issue because
> LENYA_HOME is not set to the absolute path.  Can we use
this code?
> 
>    cd `dirname $0`
>    LENYA_HOME=`pwd -P`
> 
> Is the dirname program more generically available than
the percent
> sign syntax for string manipulation?

Yeah, at least the SunOs POSIX problem will not occur.  

> 
> For the record, the rest of my original commit added a
"stop" command
> line option and automatically shut down the Lenya
instance from this
> directory before launching a new instance.  Lenya 2.0
should benefit
> from that code.

Yeah, I think so as well. Can you update the script?

I saw the test script on our zone server and would vote for
the above
subscript solution
cd `dirname $0`
LENYA_HOME=`pwd -P`

Thanks Paul.

salu2
-- 
Thorsten Scherler                                
thorsten.at.apache.org
Open Source Java                      consulting, training
and solutions


------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribelenya.apache.org
For additional commands, e-mail: dev-helplenya.apache.org


Re: Changing BRANCH_1_2_X/lenya.sh
user name
2007-12-19 11:34:13
solproviderapache.org wrote:
> On 12/11/07, Thorsten Scherler <thorstenapache.org> wrote:
>> On Thu, 2007-11-29 at 12:08 +0000, solproviderapache.org wrote:
> In English,
> 1. Get the path used to reach the current executable.
> 2. Change directory using the result of #1.  This is
relative to the
> current directory.  The current directory (PWD) is the
directory from
> which the command is called.
> 3. Get the absolute current path.  This removes dots
and symbolic links.
> 
> This code works on every *nix except SunOS.  SunOS uses
the original
> 1977 shell, which did not have good string
manipulation.  sh and awk
> were the two required programs for Unix.    String
manipulation
> required using awk.

apache are really running a SunOS server without gnutools
installed? 
wow. is it masochism, or the fear of the dreaded GPL?
>:->

i wonder: aren't dirname and basename posix? or gnuisms as
well?


-- 
Jörn Nettingsmeier

"One of my most productive days was throwing away 1000
lines of code."
   - Ken Thompson.

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribelenya.apache.org
For additional commands, e-mail: dev-helplenya.apache.org


Re: Changing BRANCH_1_2_X/lenya.sh
user name
2007-12-20 14:10:06
On 12/19/07, Jörn Nettingsmeier <nettingsapache.org> wrote:
> solproviderapache.org wrote:
> > On 12/11/07, Thorsten Scherler <thorstenapache.org> wrote:
> >> On Thu, 2007-11-29 at 12:08 +0000,
solproviderapache.org wrote:
> > In English,
> > 1. Get the path used to reach the current
executable.
> > 2. Change directory using the result of #1.  This
is relative to the
> > current directory.  The current directory (PWD) is
the directory from
> > which the command is called.
> > 3. Get the absolute current path.  This removes
dots and symbolic links.
> >
> > This code works on every *nix except SunOS.  SunOS
uses the original
> > 1977 shell, which did not have good string
manipulation.  sh and awk
> > were the two required programs for Unix.    String
manipulation
> > required using awk.
>
> apache are really running a SunOS server without
gnutools installed?
> wow. is it masochism, or the fear of the dreaded GPL?
>:->
>
> i wonder: aren't dirname and basename posix? or gnuisms
as well?
> Jörn Nettingsmeier

Not GNU.
dirname started in Unix System III.
4.3 BSD and earlier versions did not include dirname.
dirname was added to POSIX-2 (1992).

I closed the bugzilla:
http://issues.apache.org/bugzilla/show_bug.cgi?id=43748

Opened a new bugzilla for 2.0:
http://issues.apache.org/bugzilla/show_bug.cgi?id=44115

solprovider

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribelenya.apache.org
For additional commands, e-mail: dev-helplenya.apache.org


[1-8]

about | contact  Other archives ( Real Estate discussion Medical topics )