• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

catalina.sh doesn't recognized the CATALINA_BASE environment variable

 
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have CATALINA_BASE set to /home/brad/Tomcat9 in my .bashrc so it should be available to the catalina.sh script, which should in turn use my local directory as the CATALINA_BASE, which in turn should call setenv.sh, which should set the CATALINA_BASE directory. A chicken and the egg sort of problem.

Any idea why the catalina.sh script isn't reading my local environment variable for CATALINA_BASE as expected?

See, the CATALINA_BASE is set, but when I run the script the environment variable is ignored.



Since I'm unable to attach a file with a .zip, .txt, or no extension here is the important bit of the catalina.sh script.



Many thanks!
 
Saloon Keeper
Posts: 22658
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's an old release and this isn't how I usually start it, but I figured I'd check. There's no significant difference in my Tomcat7 catalina.sh script over the Tomcat9 one.

It should work. Pretty straighforward. You might try setting CATALINA_HOME to some random path or other and see what prints out. After all, I didn't actually have a /home/brad directory on my machine when I did this!
 
Tim Holloway
Saloon Keeper
Posts: 22658
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uh, come to think of it, if you didn't export CATALINA_BASE, then it probably propagate into the catalina.sh script!
 
Brad Jennings
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I've used my ~/.bashrc file to export the variable.

I'm using the Linux Mint 20 installation of Tomcat, which happens to be Tomcat9. The installer process spreads the tomcat files across the directory structure, then sets up a systemd service to automatically start tomcat. Generally I don't like it when the installer makes many of these decisions, but decided to go with it this time because there is a lack of documentation on how to follow the "Mutliple Instances" instructions in the RUNNING.txt file provided by tomcat. I followed those instructions to the best of my knowledge but ran into this chicken and the egg problem that occurs when CATALINA_BASE isn't exported beforehand.

The installer places the lion share of tomcat (pun intended) in '/usr/share/tomcat9', and then puts the web-related (a.k.a. CATALINA_BASE) files in '/var/lib'. It also creates a 'tomcat' user and group. I ended up with this set of files with permissions.





In order to create a separate instance I followed the instructions in "Advanced Configuration - Multiple Tomcat Instances" of the RUNNING.txt file that comes with Tomcat9.

In many circumstances, it is desirable to have a single copy of a Tomcat
binary distribution shared among multiple users on the same server.  To make
this possible, you can set the CATALINA_BASE environment variable to the
directory that contains the files for your 'personal' Tomcat instance.

When running with a separate CATALINA_HOME and CATALINA_BASE, the files
and directories are split as following:

In CATALINA_BASE:

* bin  - Only the following files:
          * setenv.sh (*nix) or setenv.bat (Windows),
          * tomcat-juli.jar
         The setenv scripts were described above. The tomcat-juli library
         is documented in the Logging chapter in the User Guide.
* conf - Server configuration files (including server.xml)
* lib  - Libraries and classes, as explained below
* logs - Log and output files
* webapps - Automatically loaded web applications
* work - Temporary working directories for web applications
* temp - Directory used by the JVM for temporary files (java.io.tmpdir)

In CATALINA_HOME:

* bin  - Startup and shutdown scripts
         The following files will be used only if they are absent in
         CATALINA_BASE/bin:
         setenv.sh (*nix), setenv.bat (Windows), tomcat-juli.jar
* lib  - Libraries and classes, as explained below
* endorsed - Libraries that override standard "Endorsed Standards"
             libraries provided by JRE. See Classloading documentation
             in the User Guide for details.
             This is only supported for Java <= 8.
             By default this "endorsed" directory is absent.



So, here is what I created in my Tomcat9 directory as CATALINA_BASE



My problem is that the '/usr/share/tomcat9/bin/catalina.sh' script doesn't recognize my exported CATALINA_BASE when I run the application as user 'brad'.

UPDATE: If I move the 'catalina.sh' script into my local '$CATALINA_BASE/bin' directory and then execute it from there the script will read my $CATALINA_BASE variable. I'm unsure why moving the file makes a difference. Any idea why the 'catalina.sh' in the standard directory '/usr/share/tomcat9/bin/catalina.sh' doesn't read my $CATALINA_BASE variable?
 
Tim Holloway
Saloon Keeper
Posts: 22658
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat is designed so that all of its components - both read-only and read/write are located under a single directory subtree.

But Linux conventions are that certain types of files are located in widely-separated parts of the OS filesystem tree. By using the magic of soft-linking, OS package installers can achieve both effects at the same time. The Red Hat distros work this way as well, No problem there.

Things will get a bit stickier when you attempt to run multiple Tomcat instances off a single Tomcat installation. You have a common CATALINA_BASE for all of them, but must set an independent CATALINA_HOME for each instance. CATALINA_HOME is a clone of the read/write Tomcat directories such as the webapps, work, log files and so forth.

So when you mix the legerdemain of an OS-placed Tomcat installation with the smoke-and-mirrors of multiple instances, extra care is needed to be sure that you know what's pointing at who. It's not insoluble, and in fact you can even build secondary installer packages, but it's tricky.

My best guess is that the "catalina.sh" you are actually executing is a front for the real catalina.sh and is likely pre-setting some environment variables, which it might even be picking up from someplace like an /etc/tomcat9 directory. You also ought to check to see if there's something like a /usr/bin/tomcat executable, since that's a common feature when installers customize the system.

All in all, you may want to consider uninstalling the Tomcat9 system package and installing Tomcat9 straight from the apache.org zip files. Aside from making life simpler when you're not doing a vanilla Tomcat setup, the OS packages are almost always significantly out of date relative to the official apache.org releases.
 
Brad Jennings
Greenhorn
Posts: 6
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My original quest was misdirected. I thought I needed to configure the tomcat server by hand because I was using the RUNNING.txt file which assumed the user had extracted the tarball and was running the server as 'root'. This is the...um...standard way of setting up Tomcat. But, if you're a newbie and you trust that the folks in your Linux Mint 20 are smart, then my original quest was ill guided. The Linux Mint 20 offers Tomcat9 as an install package via the Software store. Because there are many smart people creating these install packages, they don't follow the standard convention, which in turn introduced confusion. If you dig around on the internet you will find that most people grab the tarball for one reason or another and set their server up in one or two hand-crafted directories. I didn't want to follow the masses, so...

I finally figured out how to get the standard Linux Mint (Ubunutu) Tomcat9 package configured for multiple tomcat instances using Apache Netbeans 11.2. This is a scenario where you have one Tomcat on the server, and multiple development instances (ie: port 8080, 8081, 8082, etc..) in multiple Netbeans installations.  There is not one single document on the interwebs to explain how to do this, and I've been able to piece together how it should be done. It's so simple, yet so complicated it makes me sick.

CAVEAT: These instructions are the result of nearly a week of researching online for help. I've written it based on memory, so there might be some blanks that need to be filled.

STEP 1: Use the Software Manager to install the following on Linux Mint 20

1) Default-jdk
2) Netbeans (not the Flathub!!)
3) Tomcat9
4) Tomcat9-admin
5) Tomcat9-docs

STEP 2: Assuming you are NOT running every application as root do the following:

1) Run '/usr/bin/tomcat9-instance-create -p <port> -c <controlport> <catalina_base>' where <port> is an unused port, <controlport> is an unused port and <catalina_base> is a new directory under you home dir.
2) 'sudo' recursively copy '/etc/tomcat9/policy.d' to <catalina_base>/conf. Then change the permissions to your local user.
3) 'sudo' recursively copy '/etc/tomcat9/Catalina' to <catalina_base>/conf, then change the permissions to your local user.
4) edit the tomcat_users.xml and add users for admin-gui, admin-script, manager-gui,manager-script, tomcat,manager.

STEP 3: Now, run Netbeans and open the Services to add a new Web Server

1) Add Server
2) Choose Tomcat or TomEE
3) Choose Server Home is '/usr/share/tomcat9'
4) Choose Catalina Base is the same directory you chose during the 'tomcat9-instance-create' above.
5) Enter the 'manager-script' username and password you chose above.
6) Click finish.

STEP 4: Now you must edit the 'server.xml' in your 'CATALINA_BASE/conf' directory and update the Connector.

1) Open $CATALINA_BASE/conf/server.xml with nano
2) Find the "Connector" section and add a 'server' entry like so



Now that the Tomcat uses a second instance in your CATALINA_BASE, and Netbeans can connect to it, and the /conf directory contains the 'manager' application files (policy.d and Catalina folder), you should be able to start your newly created server in Netbeans. Netbeans can communicate with the second Tomcat instance via the manager app and can start/stop, build and deploy your application. When you're happy with your monster you can put the .WAR file on the primary CATALINA_HOME server for the world (or your friends) to see.



Good luck!


 
Tim Holloway
Saloon Keeper
Posts: 22658
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Congratulations! You've had an extra challenge in that Linux Mint is one of the second-tier distros so finding Mint-specific information on anything - except maybe Cinnamon! - is often difficult. However, if sounds like a lot of the Red Hat architecture has been used as a reference for their Tomcat OS packages.

Note that you shouldn't actually have to install the tomcat-admin and tomcat-doc packages. The tomcat-admin package should simply deploy Tomcat's admin webapps into TOMCAT_HOME/webapps and they are optional, as are the documentation files.

I haven't looked at NetBeans in a long, long time, so I don't know if it's able to debug apps on multiple Tomcat servers operating simultaneously. I know that Intellij couldn't, but Eclipse can. One of the reasons why I prefer Eclipse myself, in fact, since I do many evil things and multiple Tomcats are one of the lesser evils. Regardless, if you do intend to debug multiple Tomcats (regardless of what version(s) they are) hosted on a single machine, not only will you have to change the Connectors so that they don't fight over HTTP and control ports, you also have to assign a unique debugging port. This can be done via an environment variable (see catalina.sh) but I believe it's also something you can place in each instance's setenv.sh file.

As I said, I prefer to install Tomcat straight from ZIPfiles. It's a rare case where I don't rely on the OS package manager, despite the fact that I commonly do install the webapaps themselves as OS packages. That's just my preference, though.

Of course, these days, a lot of people don't mess with any of that and just build Spring Boot apps and deploy them in containers. There are a lot of people on the Ranch that have experience with that.
 
Saloon Keeper
Posts: 12428
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a cow for your efforts and for reporting back to us Brad.
 
Evil is afoot. But this tiny ad is just an ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic