You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by is...@apache.org on 2018/07/01 18:44:38 UTC
svn commit: r1834798 - in /tomcat/trunk/bin: makebase.bat makebase.sh
Author: isapir
Date: Sun Jul 1 18:44:38 2018
New Revision: 1834798
URL: http://svn.apache.org/viewvc?rev=1834798&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62500
Added scripts to create CATALINA_BASE directory
Added:
tomcat/trunk/bin/makebase.bat
tomcat/trunk/bin/makebase.sh
Added: tomcat/trunk/bin/makebase.bat
URL: http://svn.apache.org/viewvc/tomcat/trunk/bin/makebase.bat?rev=1834798&view=auto
==============================================================================
--- tomcat/trunk/bin/makebase.bat (added)
+++ tomcat/trunk/bin/makebase.bat Sun Jul 1 18:44:38 2018
@@ -0,0 +1,63 @@
+:: Licensed to the Apache Software Foundation (ASF) under one or more
+:: contributor license agreements. See the NOTICE file distributed with
+:: this work for additional information regarding copyright ownership.
+:: The ASF licenses this file to You under the Apache License, Version 2.0
+:: (the "License"); you may not use this file except in compliance with
+:: the License. You may obtain a copy of the License at
+::
+:: http://www.apache.org/licenses/LICENSE-2.0
+::
+:: Unless required by applicable law or agreed to in writing, software
+:: distributed under the License is distributed on an "AS IS" BASIS,
+:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+:: See the License for the specific language governing permissions and
+:: limitations under the License.
+
+:: This script creates the directory structure required for running Tomcat
+:: in a separate directory by pointing %CATALINA_BASE% to it. It copies the
+:: conf directory from %CATALINA_HOME%, and creates empty directories for
+:: logs, temp, and work.
+::
+:: If the file %CATALINA_HOME%/bin/setenv.sh exists then it is copied to
+:: the target directory as well.
+
+@echo off
+
+:: first arg is the target directory
+set BASE_TGT=%1
+
+if %BASE_TGT%.==. (
+ :: target directory not provided; exit
+ echo "Usage: makebase <path-to-target-directory>"
+ goto :EOF
+)
+
+set CURR_DIR=%~dp0
+set HOME_DIR=%CURR_DIR%..\
+
+if exist %BASE_TGT% (
+ :: target directory exists
+ echo directory exists
+
+ :: exit if target directory is not empty
+ for /F %%i in ('dir /b "%BASE_TGT%\*.*"') do (
+ echo target directory is not empty
+ goto :EOF
+ )
+) else (
+ :: create the target directory
+ mkdir %BASE_TGT%
+)
+
+:: create empty directories for bin, logs, temp, and work
+mkdir %BASE_TGT%\bin %BASE_TGT%\logs %BASE_TGT%\temp %BASE_TGT%\work
+
+:: copy conf directory
+robocopy %HOME_DIR%\conf %BASE_TGT%\conf > nul
+
+:: copy setenv.bat if exists
+robocopy %HOME_DIR%\bin %BASE_TGT%\bin setenv.bat > nul
+
+echo created CATALINA_BASE directory at $BASE_TGT
+
+:EOF
Added: tomcat/trunk/bin/makebase.sh
URL: http://svn.apache.org/viewvc/tomcat/trunk/bin/makebase.sh?rev=1834798&view=auto
==============================================================================
--- tomcat/trunk/bin/makebase.sh (added)
+++ tomcat/trunk/bin/makebase.sh Sun Jul 1 18:44:38 2018
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This script creates the directory structure required for running Tomcat
+# in a separate directory by pointing $CATALINA_BASE to it. It copies the
+# conf directory from $CATALINA_HOME, and creates empty directories for
+# bin, logs, temp, and work.
+#
+# If the file $CATALINA_HOME/bin/setenv.sh exists then it is copied to
+# the target directory as well.
+
+# first arg is the target directory
+BASE_TGT=$1
+
+if [ -z ${BASE_TGT} ]; then
+ # target directory not provided; exit
+ echo "Usage: makebase <path-to-target-directory>"
+ exit 1
+fi
+
+HOME_DIR="$(dirname $(dirname $0))"
+
+if [ -d ${BASE_TGT} ]; then
+ # target directory exists
+ echo directory exists
+
+ # exit if target directory is not empty
+ [ "$(ls -A ${BASE_TGT})" ] && \
+ echo "target directory is not empty" && \
+ exit 1
+else
+ # create the target directory
+ mkdir -p ${BASE_TGT}
+fi
+
+for dir in bin logs temp work;
+do
+ # copy directory with permissions and delete contents if any
+ cp -a "${HOME_DIR}/${dir}" "${BASE_TGT}/${dir}"
+ rm -fr "${BASE_TGT}/${dir}"/*
+done
+
+# copy conf directory recursively and preserve permissions
+cp -a "${HOME_DIR}/conf" "${BASE_TGT}/"
+
+# copy setenv.sh if exists
+[ -f "${HOME_DIR}/bin/setenv.sh" ] && \
+ cp -p "${HOME_DIR}/bin/setenv.sh" "${BASE_TGT}/bin/"
+
+echo created CATALINA_BASE directory at $BASE_TGT
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1834798 - in /tomcat/trunk/bin: makebase.bat
makebase.sh
Posted by Michael Osipov <mi...@apache.org>.
Am 2018-07-01 um 21:33 schrieb Igal Sapir:
> On 7/1/2018 12:18 PM, Michael Osipov wrote:
>> Am 2018-07-01 um 20:44 schrieb isapir@apache.org:
>>> Author: isapir
>>> Date: Sun Jul 1 18:44:38 2018
>>> New Revision: 1834798
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1834798&view=rev
>>> Log:
>>> Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62500
>>> Added scripts to create CATALINA_BASE directory
>>>
>>> Added:
>>> tomcat/trunk/bin/makebase.bat
>>> tomcat/trunk/bin/makebase.sh
>>>
>>> Added: tomcat/trunk/bin/makebase.sh
>>> URL:
>>> http://svn.apache.org/viewvc/tomcat/trunk/bin/makebase.sh?rev=1834798&view=auto
>>>
>>> ==============================================================================
>>>
>>> --- tomcat/trunk/bin/makebase.sh (added)
>>> +++ tomcat/trunk/bin/makebase.sh Sun Jul 1 18:44:38 2018
>>> @@ -0,0 +1,64 @@
>>> +#!/bin/sh
>>> +
>>> +# Licensed to the Apache Software Foundation (ASF) under one or more
>>> +# contributor license agreements. See the NOTICE file distributed with
>>> +# this work for additional information regarding copyright ownership.
>>> +# The ASF licenses this file to You under the Apache License,
>>> Version 2.0
>>> +# (the "License"); you may not use this file except in compliance with
>>> +# the License. You may obtain a copy of the License at
>>> +#
>>> +# http://www.apache.org/licenses/LICENSE-2.0
>>> +#
>>> +# Unless required by applicable law or agreed to in writing, software
>>> +# distributed under the License is distributed on an "AS IS" BASIS,
>>> +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>>> implied.
>>> +# See the License for the specific language governing permissions and
>>> +# limitations under the License.
>>> +
>>> +# This script creates the directory structure required for running
>>> Tomcat
>>> +# in a separate directory by pointing $CATALINA_BASE to it. It
>>> copies the
>>> +# conf directory from $CATALINA_HOME, and creates empty directories for
>>> +# bin, logs, temp, and work.
>>> +#
>>> +# If the file $CATALINA_HOME/bin/setenv.sh exists then it is copied to
>>> +# the target directory as well.
>>> +
>>> +# first arg is the target directory
>>> +BASE_TGT=$1
>>
>> Why not call it CATALINA_BASE?
>>
>>> +if [ -z ${BASE_TGT} ]; then
>>> + # target directory not provided; exit
>>> + echo "Usage: makebase <path-to-target-directory>"
>>> + exit 1
>>> +fi
>>> +
>>> +HOME_DIR="$(dirname $(dirname $0))"
>>
>> Why not call it CATALINA_HOME?
>
> I was thinking that if CATALINA_BASE or CATALINA_HOME are already set
> then I shouldn't mess with them.
You could test that and make it idiotproof, but at the end you can
ignore an external CATALINA_HOME because this script is an
implementation detail of the parent CATALINA_HOME and shall not be seen
as portable. CATALINA_BASE could be an alternative to $1:
CATALINA_BASE=${CATALINA_BASE:1} or similar.
>>
>>> +if [ -d ${BASE_TGT} ]; then
>>> + # target directory exists
>>> + echo directory exists
>>
>> Why no double quotes? Why not "target directory exists"?
>
> Will update accordingly, but do the quotes add anything? It seems to
> work fine without them.
You should make your strings consistent. Look below, they are quoted.
>>
>>> + # exit if target directory is not empty
>>> + [ "$(ls -A ${BASE_TGT})" ] && \
>>> + echo "target directory is not empty" && \
>>> + exit 1
>>> +else
>>> + # create the target directory
>>> + mkdir -p ${BASE_TGT}
>>> +fi
>>> +
>>> +for dir in bin logs temp work;
>>
>> Why not webapps? The default Tomcat config (server.xml) refers to
>> webapps in CATALINA_BASE. lib is missing: catalina.properties
>> common.loader refers to it.
>
> webapps make sense, though we might want to allow to create an empty
> directory rather than copy the contents of the original webapps.
I don't expect you to copy the webapps itself, but have webapps/ dir
created already. The user can decide to link or to copy manager/. I do
link only at work because my manager app is globally configured.
> I don't believe that `lib` is required. I have deployed many instances
> without `lib` and never noticed an issue. Am I missing something?
It is not required, but if a user wants to have private libs or override
something from Tomcat, this should work out of the box.
catalina.properties allows that.
>>
>>> +do
>>> + # copy directory with permissions and delete contents if any
>>> + cp -a "${HOME_DIR}/${dir}" "${BASE_TGT}/${dir}"
>>> + rm -fr "${BASE_TGT}/${dir}"/*
>>> +done
>>
>> Why do you copy and then delete? Why not mkdir directory directly?
>
> On Windows I create the directories. On *nix the permissions were
> different so I did it that way to copy the original permissions. I was
> also thinking of using `chmod` as a different option.
I wouldn't preserve the permissions because you shouldn't make any
assumptions on the target. If you want to go that route with chmod,
you'll need for files *and* directories, plus for consistency, I'd
expect you to have chown support too. Leave both to the user for now.
>>
>>> +# copy conf directory recursively and preserve permissions
>>> +cp -a "${HOME_DIR}/conf" "${BASE_TGT}/"
>>
>> Preserving permissions will fail if the target is not under root's
>> control. E.g., a user wants a private Tomcat. He won't be able to work
>> with.
>
> So should I not preserve permissions and instead use `mkdir` and `chmod`?
Use mkdir and don't use chmod, unless you exactly know what the user wants.
>>
>>> +# copy setenv.sh if exists
>>> +[ -f "${HOME_DIR}/bin/setenv.sh" ] && \
>>> + cp -p "${HOME_DIR}/bin/setenv.sh" "${BASE_TGT}/bin/"
>>
>> Here you ignore -p.
>>
>>> +echo created CATALINA_BASE directory at $BASE_TGT
>>
>> Not quoted again.
>>
>> You should also warn that the ports in the server.xml are likely bound
>> already.
>
> I'll add that
I have that portion in my scripts, but it is not portable.
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1834798 - in /tomcat/trunk/bin: makebase.bat
makebase.sh
Posted by Igal Sapir <is...@apache.org>.
On 7/1/2018 12:18 PM, Michael Osipov wrote:
> Am 2018-07-01 um 20:44 schrieb isapir@apache.org:
>> Author: isapir
>> Date: Sun Jul 1 18:44:38 2018
>> New Revision: 1834798
>>
>> URL: http://svn.apache.org/viewvc?rev=1834798&view=rev
>> Log:
>> Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62500
>> Added scripts to create CATALINA_BASE directory
>>
>> Added:
>> tomcat/trunk/bin/makebase.bat
>> tomcat/trunk/bin/makebase.sh
>>
>> Added: tomcat/trunk/bin/makebase.sh
>> URL:
>> http://svn.apache.org/viewvc/tomcat/trunk/bin/makebase.sh?rev=1834798&view=auto
>> ==============================================================================
>>
>> --- tomcat/trunk/bin/makebase.sh (added)
>> +++ tomcat/trunk/bin/makebase.sh Sun Jul 1 18:44:38 2018
>> @@ -0,0 +1,64 @@
>> +#!/bin/sh
>> +
>> +# Licensed to the Apache Software Foundation (ASF) under one or more
>> +# contributor license agreements. See the NOTICE file distributed with
>> +# this work for additional information regarding copyright ownership.
>> +# The ASF licenses this file to You under the Apache License,
>> Version 2.0
>> +# (the "License"); you may not use this file except in compliance with
>> +# the License. You may obtain a copy of the License at
>> +#
>> +# http://www.apache.org/licenses/LICENSE-2.0
>> +#
>> +# Unless required by applicable law or agreed to in writing, software
>> +# distributed under the License is distributed on an "AS IS" BASIS,
>> +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
>> implied.
>> +# See the License for the specific language governing permissions and
>> +# limitations under the License.
>> +
>> +# This script creates the directory structure required for running
>> Tomcat
>> +# in a separate directory by pointing $CATALINA_BASE to it. It
>> copies the
>> +# conf directory from $CATALINA_HOME, and creates empty directories for
>> +# bin, logs, temp, and work.
>> +#
>> +# If the file $CATALINA_HOME/bin/setenv.sh exists then it is copied to
>> +# the target directory as well.
>> +
>> +# first arg is the target directory
>> +BASE_TGT=$1
>
> Why not call it CATALINA_BASE?
>
>> +if [ -z ${BASE_TGT} ]; then
>> + # target directory not provided; exit
>> + echo "Usage: makebase <path-to-target-directory>"
>> + exit 1
>> +fi
>> +
>> +HOME_DIR="$(dirname $(dirname $0))"
>
> Why not call it CATALINA_HOME?
I was thinking that if CATALINA_BASE or CATALINA_HOME are already set
then I shouldn't mess with them.
>
>> +if [ -d ${BASE_TGT} ]; then
>> + # target directory exists
>> + echo directory exists
>
> Why no double quotes? Why not "target directory exists"?
Will update accordingly, but do the quotes add anything? It seems to
work fine without them.
>
>> + # exit if target directory is not empty
>> + [ "$(ls -A ${BASE_TGT})" ] && \
>> + echo "target directory is not empty" && \
>> + exit 1
>> +else
>> + # create the target directory
>> + mkdir -p ${BASE_TGT}
>> +fi
>> +
>> +for dir in bin logs temp work;
>
> Why not webapps? The default Tomcat config (server.xml) refers to
> webapps in CATALINA_BASE. lib is missing: catalina.properties
> common.loader refers to it.
webapps make sense, though we might want to allow to create an empty
directory rather than copy the contents of the original webapps.
I don't believe that `lib` is required. I have deployed many instances
without `lib` and never noticed an issue. Am I missing something?
>
>> +do
>> + # copy directory with permissions and delete contents if any
>> + cp -a "${HOME_DIR}/${dir}" "${BASE_TGT}/${dir}"
>> + rm -fr "${BASE_TGT}/${dir}"/*
>> +done
>
> Why do you copy and then delete? Why not mkdir directory directly?
On Windows I create the directories. On *nix the permissions were
different so I did it that way to copy the original permissions. I was
also thinking of using `chmod` as a different option.
>
>> +# copy conf directory recursively and preserve permissions
>> +cp -a "${HOME_DIR}/conf" "${BASE_TGT}/"
>
> Preserving permissions will fail if the target is not under root's
> control. E.g., a user wants a private Tomcat. He won't be able to work
> with.
So should I not preserve permissions and instead use `mkdir` and `chmod`?
>
>> +# copy setenv.sh if exists
>> +[ -f "${HOME_DIR}/bin/setenv.sh" ] && \
>> + cp -p "${HOME_DIR}/bin/setenv.sh" "${BASE_TGT}/bin/"
>
> Here you ignore -p.
>
>> +echo created CATALINA_BASE directory at $BASE_TGT
>
> Not quoted again.
>
> You should also warn that the ports in the server.xml are likely bound
> already.
I'll add that
Igal
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1834798 - in /tomcat/trunk/bin: makebase.bat
makebase.sh
Posted by Michael Osipov <mi...@apache.org>.
Am 2018-07-01 um 20:44 schrieb isapir@apache.org:
> Author: isapir
> Date: Sun Jul 1 18:44:38 2018
> New Revision: 1834798
>
> URL: http://svn.apache.org/viewvc?rev=1834798&view=rev
> Log:
> Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62500
> Added scripts to create CATALINA_BASE directory
>
> Added:
> tomcat/trunk/bin/makebase.bat
> tomcat/trunk/bin/makebase.sh
>
> Added: tomcat/trunk/bin/makebase.sh
> URL: http://svn.apache.org/viewvc/tomcat/trunk/bin/makebase.sh?rev=1834798&view=auto
> ==============================================================================
> --- tomcat/trunk/bin/makebase.sh (added)
> +++ tomcat/trunk/bin/makebase.sh Sun Jul 1 18:44:38 2018
> @@ -0,0 +1,64 @@
> +#!/bin/sh
> +
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements. See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.
> +# The ASF licenses this file to You under the Apache License, Version 2.0
> +# (the "License"); you may not use this file except in compliance with
> +# the License. You may obtain a copy of the License at
> +#
> +# http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS,
> +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +# See the License for the specific language governing permissions and
> +# limitations under the License.
> +
> +# This script creates the directory structure required for running Tomcat
> +# in a separate directory by pointing $CATALINA_BASE to it. It copies the
> +# conf directory from $CATALINA_HOME, and creates empty directories for
> +# bin, logs, temp, and work.
> +#
> +# If the file $CATALINA_HOME/bin/setenv.sh exists then it is copied to
> +# the target directory as well.
> +
> +# first arg is the target directory
> +BASE_TGT=$1
Why not call it CATALINA_BASE?
> +if [ -z ${BASE_TGT} ]; then
> + # target directory not provided; exit
> + echo "Usage: makebase <path-to-target-directory>"
> + exit 1
> +fi
> +
> +HOME_DIR="$(dirname $(dirname $0))"
Why not call it CATALINA_HOME?
> +if [ -d ${BASE_TGT} ]; then
> + # target directory exists
> + echo directory exists
Why no double quotes? Why not "target directory exists"?
> + # exit if target directory is not empty
> + [ "$(ls -A ${BASE_TGT})" ] && \
> + echo "target directory is not empty" && \
> + exit 1
> +else
> + # create the target directory
> + mkdir -p ${BASE_TGT}
> +fi
> +
> +for dir in bin logs temp work;
Why not webapps? The default Tomcat config (server.xml) refers to
webapps in CATALINA_BASE. lib is missing: catalina.properties
common.loader refers to it.
> +do
> + # copy directory with permissions and delete contents if any
> + cp -a "${HOME_DIR}/${dir}" "${BASE_TGT}/${dir}"
> + rm -fr "${BASE_TGT}/${dir}"/*
> +done
Why do you copy and then delete? Why not mkdir directory directly?
> +# copy conf directory recursively and preserve permissions
> +cp -a "${HOME_DIR}/conf" "${BASE_TGT}/"
Preserving permissions will fail if the target is not under root's
control. E.g., a user wants a private Tomcat. He won't be able to work with.
> +# copy setenv.sh if exists
> +[ -f "${HOME_DIR}/bin/setenv.sh" ] && \
> + cp -p "${HOME_DIR}/bin/setenv.sh" "${BASE_TGT}/bin/"
Here you ignore -p.
> +echo created CATALINA_BASE directory at $BASE_TGT
Not quoted again.
You should also warn that the ports in the server.xml are likely bound
already.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org