Implications of setting createDirs attribute on host declarations to false in Tomcat

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Implications of setting createDirs attribute on host declarations to false in Tomcat

Paul-2
Hello,

When running Tomcat in a Docker container as non-root, I'm getting an
error entry in the logs:

Unable to create directory for deployment:
[/usr/local/tomcat/conf/Catalina/localhost]
I traced this down to the aforementioned directory not being there when
Tomcat gets launched and the user running Tomcat does not having the
permissions to create the directory.

I also traced where this error message is coming from and its due to the
createDirs attribute on the host declaration in server.xml not being set
to false. The docs for the createDirs property states that if its set to
true (the default) it'll attempt to create some directories, log an
error when it fails, but the failure wont stop the startup of Tomcat.

But what I cannot find anywhere is why those directories are created in
the first place and what the ramifications are of them not being created
when createDirs is set to false.

This question is for Tomcat docker images in general (in order to
determine whether generic Tomcat Docker images should do something
different to prevent these Errors in the logs), in my specific scenario
however I'm running one webapp: an exploded WAR in the webapps/ROOT
directory, which comes with its on context.xml in
/webapps/ROOT/META-INF/context.xml

TIA

Paul



--
This email has been checked for viruses by AVG.
https://www.avg.com
Reply | Threaded
Open this post in threaded view
|

Re: Implications of setting createDirs attribute on host declarations to false in Tomcat

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Paul,

On 8/31/20 05:36, Paul wrote:

> Hello,
>
> When running Tomcat in a Docker container as non-root, I'm getting
> an error entry in the logs:
>
> Unable to create directory for deployment:
> [/usr/local/tomcat/conf/Catalina/localhost] I traced this down to
> the aforementioned directory not being there when Tomcat gets
> launched and the user running Tomcat does not having the
> permissions to create the directory.
>
> I also traced where this error message is coming from and its due
> to the createDirs attribute on the host declaration in server.xml
> not being set to false. The docs for the createDirs property states
> that if its set to true (the default) it'll attempt to create some
> directories, log an error when it fails, but the failure wont stop
> the startup of Tomcat.
>
> But what I cannot find anywhere is why those directories are
> created in the first place and what the ramifications are of them
> not being created when createDirs is set to false.

You are deploying a WAR file, right?

If you don't set createDirs="true" then Tomcat will not be able to
unpack WAR files for you.

> This question is for Tomcat docker images in general (in order to
> determine whether generic Tomcat Docker images should do something
> different to prevent these Errors in the logs), in my specific
> scenario however I'm running one webapp: an exploded WAR in the
> webapps/ROOT directory, which comes with its on context.xml in
> /webapps/ROOT/META-INF/context.xml

If webapps/ already exists, what directory is Tomcat trying to create?
conf/[engine]/[host]?

Can you arrange for conf/[engine]/[host] (usually
conf/Catalina/localhost) to exist so that the setting for createDirs
doesn't matter?

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl9NFjoACgkQHPApP6U8
pFi/7xAAs6Rg39EWDFLkL2DutF4sGu6MeB9lwaRxq/OmsubS5X44+w+kFGha05fx
wHYFe6vhl6WL+UEIo/bja+JRgQCTCDTYf6fMmPYvJ6am/b2Ew0GmtjQlU6eimH2y
uGM/sfT0No+FYRpAxW9mbsh86H6rYMBNvj+dNWeusSkS/3uX2cELm/WwDKnOQb9I
bX5ZxgsA2DlXP37Zn+Q3G1bjP71Wbx1C/pbiXCYL3tGq3RLalBY3Y++GoTjAtEkX
4/jBNqLGBwgmFKQY0pfEc9iNCgwbgMh85zAvvUkzIxt+oKxYQLWPDwjs5Krfu2ZK
/pUIFey33rqAO9Vo2iuyX8W03kU0hhAK0PIXimPW8H3848o4Qe+5mJt46jrcpAb7
DFGZUiwS7plD9UrTZpY4UGfWtwAx1GwD9Db/l50Ru32mVtbYgvfzYKqKfZKe7hbI
gOUjIu+5jk0cgUE8d+bK2kiTnX5CQJNHT2N44y1/HLRBtuS7RX5e7yLuQfLZ6yeI
YpmQAr5oxccQ4XSbL9XQMtckG46JqSL1GwbejMT4n0pMzj7zI8J2Eeh3hCsov5bL
trDml0upYcWFoLNUJhFn+Lo1a0ujqOlH2iKS0xg+RU37t0mH0U8/ys77ZS12cnk8
bbwztsxUVPHKc2VjKOMhn47v+cmeGhAP6zeB2ZZ7O9fv3Si9xOQ=
=g5QV
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Implications of setting createDirs attribute on host declarations to false in Tomcat

Paul-2
In reply to this post by Paul-2
Hi Chris,

First of all tnx for your response.

For my own purpose it was about the conf/[engine]/[host] folder and I'm
now creating that in my dockerfile and thus I got rid of the error.

However, this question is not so much to solve it for just myself, but
more to be able to give proper directions to anyone dockerizing Tomcat
or providing 'generic' Tomcat base images.

I'm guessing whether or not to turn of createDirs really depends on how
Tomcat is used to deploy webapps/war files and whether or not turning
off createDirs will cause issues on startup/at runtime might depends on
how hosts are defined (unpackWAR/autoDeploy/deployOnStartup settings),
but the exact correlation is unclear to me and I cannot find any
documentation on it.

> You are deploying a WAR file, right?
yes, but I already unzip the WAR into the /webapps folder while
dockerizing my entire application > If you don't set createDirs="true" then Tomcat will not be able to unpack WAR files for you.

Which folders does Tomcat depend on for the deployment of WAR files
then? The standard Tomcat download comes with the following:

<Engine name="Catalina" defaultHost="localhost">
       <Host name="localhost"  appBase="webapps"
             unpackWARs="true" autoDeploy="true">

And already has the webapps folder in the distribution.

Am I correct in saying that createDirs="true" would make sure the
/webapps and /conf/Catalina/localhost directories exist on startup? Or
any other directory of you'd configure other engines/hosts?

And when does Tomcat utilize the conf/[engine]/[host] folder? As I
mentioned before I resolved the error in the logs for my own purpose by
just creating the missing directory while dockerizing my app, but afaics
Tomcat never writes something to it, which makes me think that the
folder is only used in certain circumstances.

Again: my goal is to get clear what Tomcat needs in different scenarios,
thus things can be done correctly in generic Tomcat docker base images
and/or provide proper instructions with those base images as to how
(re)configure/adjust the base images based on the different usages.

Maybe it'd make sense to add such clarifications to the Tomcat docs as
well (I'd be willing to create a PR)

TIA,

Paul


On 8/31/2020 5:24 PM, Christopher Schultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Paul,
>
> On 8/31/20 05:36, Paul wrote:
>> Hello,
>>
>> When running Tomcat in a Docker container as non-root, I'm getting
>> an error entry in the logs:
>>
>> Unable to create directory for deployment:
>> [/usr/local/tomcat/conf/Catalina/localhost] I traced this down to
>> the aforementioned directory not being there when Tomcat gets
>> launched and the user running Tomcat does not having the
>> permissions to create the directory.
>>
>> I also traced where this error message is coming from and its due
>> to the createDirs attribute on the host declaration in server.xml
>> not being set to false. The docs for the createDirs property states
>> that if its set to true (the default) it'll attempt to create some
>> directories, log an error when it fails, but the failure wont stop
>> the startup of Tomcat.
>>
>> But what I cannot find anywhere is why those directories are
>> created in the first place and what the ramifications are of them
>> not being created when createDirs is set to false.
> You are deploying a WAR file, right?
>
> If you don't set createDirs="true" then Tomcat will not be able to
> unpack WAR files for you.
>
>> This question is for Tomcat docker images in general (in order to
>> determine whether generic Tomcat Docker images should do something
>> different to prevent these Errors in the logs), in my specific
>> scenario however I'm running one webapp: an exploded WAR in the
>> webapps/ROOT directory, which comes with its on context.xml in
>> /webapps/ROOT/META-INF/context.xml
> If webapps/ already exists, what directory is Tomcat trying to create?
> conf/[engine]/[host]?
>
> Can you arrange for conf/[engine]/[host] (usually
> conf/Catalina/localhost) to exist so that the setting for createDirs
> doesn't matter?
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: Using GnuPG with Thunderbird -https://www.enigmail.net/
>
> iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl9NFjoACgkQHPApP6U8
> pFi/7xAAs6Rg39EWDFLkL2DutF4sGu6MeB9lwaRxq/OmsubS5X44+w+kFGha05fx
> wHYFe6vhl6WL+UEIo/bja+JRgQCTCDTYf6fMmPYvJ6am/b2Ew0GmtjQlU6eimH2y
> uGM/sfT0No+FYRpAxW9mbsh86H6rYMBNvj+dNWeusSkS/3uX2cELm/WwDKnOQb9I
> bX5ZxgsA2DlXP37Zn+Q3G1bjP71Wbx1C/pbiXCYL3tGq3RLalBY3Y++GoTjAtEkX
> 4/jBNqLGBwgmFKQY0pfEc9iNCgwbgMh85zAvvUkzIxt+oKxYQLWPDwjs5Krfu2ZK
> /pUIFey33rqAO9Vo2iuyX8W03kU0hhAK0PIXimPW8H3848o4Qe+5mJt46jrcpAb7
> DFGZUiwS7plD9UrTZpY4UGfWtwAx1GwD9Db/l50Ru32mVtbYgvfzYKqKfZKe7hbI
> gOUjIu+5jk0cgUE8d+bK2kiTnX5CQJNHT2N44y1/HLRBtuS7RX5e7yLuQfLZ6yeI
> YpmQAr5oxccQ4XSbL9XQMtckG46JqSL1GwbejMT4n0pMzj7zI8J2Eeh3hCsov5bL
> trDml0upYcWFoLNUJhFn+Lo1a0ujqOlH2iKS0xg+RU37t0mH0U8/ys77ZS12cnk8
> bbwztsxUVPHKc2VjKOMhn47v+cmeGhAP6zeB2ZZ7O9fv3Si9xOQ=
> =g5QV
> -----END PGP SIGNATURE-----


--
This email has been checked for viruses by AVG.
https://www.avg.com
Reply | Threaded
Open this post in threaded view
|

Re: Implications of setting createDirs attribute on host declarations to false in Tomcat

markt
On 01/09/2020 08:42, Paul wrote:

> Hi Chris,
>
> First of all tnx for your response.
>
> For my own purpose it was about the conf/[engine]/[host] folder and I'm
> now creating that in my dockerfile and thus I got rid of the error.
>
> However, this question is not so much to solve it for just myself, but
> more to be able to give proper directions to anyone dockerizing Tomcat
> or providing 'generic' Tomcat base images.
>
> I'm guessing whether or not to turn of createDirs really depends on how
> Tomcat is used to deploy webapps/war files and whether or not turning
> off createDirs will cause issues on startup/at runtime might depends on
> how hosts are defined (unpackWAR/autoDeploy/deployOnStartup settings),
> but the exact correlation is unclear to me and I cannot find any
> documentation on it.

createDirs was added so that directory creation was triggered early and
any associated errors occurred during start-up rather than at some point
later during an automatic deployment.

The directories are only required if:
a) Tomcat is configured to extract the context.xml file from a WAR
   and copy it to the defined xmlBase for the Host. This will only
   happen if copyXML is true (defaults to false) and deployXML is
   true.
or
b) You want to define Contexts (web applications) via external
   context.xml files

See http://tomcat.apache.org/tomcat-10.0-doc/config/host.html

> Which folders does Tomcat depend on for the deployment of WAR files
> then? The standard Tomcat download comes with the following:
>
> <Engine name="Catalina" defaultHost="localhost">
>       <Host name="localhost"  appBase="webapps"
>             unpackWARs="true" autoDeploy="true">
>
> And already has the webapps folder in the distribution.
>
> Am I correct in saying that createDirs="true" would make sure the
> /webapps

No.

> and /conf/Catalina/localhost directories exist on startup?

Yes.

> Or any other directory of you'd configure other engines/hosts?

No.

> And when does Tomcat utilize the conf/[engine]/[host] folder? As I
> mentioned before I resolved the error in the logs for my own purpose by
> just creating the missing directory while dockerizing my app, but afaics
> Tomcat never writes something to it, which makes me think that the
> folder is only used in certain circumstances.

See above. You can also place appropriately named context.xml files
there yourself.

See
http://tomcat.apache.org/tomcat-10.0-doc/config/host.html#Automatic_Application_Deployment

and

http://tomcat.apache.org/tomcat-10.0-doc/config/automatic-deployment.html

> Again: my goal is to get clear what Tomcat needs in different scenarios,
> thus things can be done correctly in generic Tomcat docker base images
> and/or provide proper instructions with those base images as to how
> (re)configure/adjust the base images based on the different usages.
>
> Maybe it'd make sense to add such clarifications to the Tomcat docs as
> well (I'd be willing to create a PR)
>
> TIA,
>
> Paul
>
>
> On 8/31/2020 5:24 PM, Christopher Schultz wrote:
> Paul,
>
> On 8/31/20 05:36, Paul wrote:
>>>> Hello,
>>>>
>>>> When running Tomcat in a Docker container as non-root, I'm getting
>>>> an error entry in the logs:
>>>>
>>>> Unable to create directory for deployment:
>>>> [/usr/local/tomcat/conf/Catalina/localhost] I traced this down to
>>>> the aforementioned directory not being there when Tomcat gets
>>>> launched and the user running Tomcat does not having the
>>>> permissions to create the directory.
>>>>
>>>> I also traced where this error message is coming from and its due
>>>> to the createDirs attribute on the host declaration in server.xml
>>>> not being set to false. The docs for the createDirs property states
>>>> that if its set to true (the default) it'll attempt to create some
>>>> directories, log an error when it fails, but the failure wont stop
>>>> the startup of Tomcat.
>>>>
>>>> But what I cannot find anywhere is why those directories are
>>>> created in the first place and what the ramifications are of them
>>>> not being created when createDirs is set to false.
> You are deploying a WAR file, right?
>
> If you don't set createDirs="true" then Tomcat will not be able to
> unpack WAR files for you.
>
>>>> This question is for Tomcat docker images in general (in order to
>>>> determine whether generic Tomcat Docker images should do something
>>>> different to prevent these Errors in the logs), in my specific
>>>> scenario however I'm running one webapp: an exploded WAR in the
>>>> webapps/ROOT directory, which comes with its on context.xml in
>>>> /webapps/ROOT/META-INF/context.xml
> If webapps/ already exists, what directory is Tomcat trying to create?
> conf/[engine]/[host]?
>
> Can you arrange for conf/[engine]/[host] (usually
> conf/Catalina/localhost) to exist so that the setting for createDirs
> doesn't matter?
>
> -chris
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]