• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difficulties getting Tomcat 10 to run on boot, Rasp pi.

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want Tomcat 10 to run when my Pi boots up.  I've found all kinds of scripts that I've copied and pasted to try to get things running, and am partially enlightened by this excellent find: https://jdebp.uk/FGA/systemd-house-of-horror/tomcat.html

I'm still getting the horrors though - due to my ignorance of Linux.

Following the recommendations of the link above, I made a tomcat.service file like this:



but get this result:


I see the bootstrap jar is in Cataline_home/bin. I've tried with and without the bin.

I've also tried:



and get this:





Can someone help please?

 
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ick.

To start Tomcat, all you need is an ExecStart=TOMCAT_HOME/bin/startup.sh, where TOMCAT_HOME is the directory path where Tomcat was unzipped. For example, /usr/local/apache-tomcat. Your tomcat directory name may vary, of course, and I usually softflink a simple name like "tomcat9" to the actual tomcat unzip name for simplicity, but that's just a shortcut.

You should not set any environment variables for Tomcat applications. And while it's true that you can set JAVA_HOME, JDK_HOME, CATALINA_HOME, and CATALINA_BASE plus other environment variables that the catalina.sh script looks for, in most cases, leaving them unset will cause Tomcat to deduce all it needs to know. Anything else, make a "setenv.sh" script in TOMCAT_HOME/bin and put them there. For the external stuff like JAVA_HOME, and JPDA you can define "Environment=" statements in the Service section of your systemd file.

The shutdown command for Tomcat is TOMCAT_HOME/bin/shutdown.sh. If you want to get fancy you might play around with the CATALINA_PID and PIDFile systemd stuff, but tomcat runs off control port 8000, so it probably won't help much, if any.
 
John Peders
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh boy, what a simple and clear answer after all the rigmarole I've been through

THANK YOU!
 
John Peders
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh no! Spoke too soon. I was so pleased when I ran "sudo systemctl status tomcat.service" and saw Tomcat had started. But in my browser I get site can't be reached..

I figured if I just remove the classpath settings I had put in .bashrc I'd be up and running.

But that didn't help.

Here's the output I get in response to "sudo systemctl status tomcat.service":



Active: inactive (dead) looks suspicious to me.

Anyway, if I run "sudo /opt/tomcat/bin/startup.sh" Tomcat runs fine, and shows this output:



And I get the right results in the browser.

I figured I'd try to copy those settings listed above in .bashrc with these lines:


But still, Tomcat doesn't run on startup.

Here's all that's in my tomcat.service file now:



??
 
Tim Holloway
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Best bet is to tear out all the hacks and start clean. What does the catalina.out log tell you when you try and start as a service?

And incidentally, systemd does not run via bash, so bash settings won't help you.
 
John Peders
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've taken out the hacks.

What I  have left is file called tomcat in /etc/default with the contents:

JAVA_HOME=/snap/openjdk/715/jdk/bin

and the unit file tomcat.service in /etc/systemd/system

with the contents:

[Unit]
Description=Apache Tomcat Web Application Container

[Service]
ExecStart=/opt/tomcat/bin/startup.sh

[Install]
WantedBy=multi-user.target

There is nothing new in catalina.out (since yesterday anyway) when I closed tomcat manually.

The  output from command journalctl -xe:



I wish it wouldn't successfully enter the dead state! So much success, so little actually happening!




 
Tim Holloway
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couple of things come to mind.

First of all, did you install Tomcat by downloading a ZIP or tarball from tomcat apache.org or did you use apt/dpkg to install a Raspi-specific package? If you did a vanilla (download) install, then /etc/default would not be used. And in any event, according to Catalina, it didn't use that, it used "/usr" as JAVA_HOME. Which it should. Although check with the "/usr/bin/java -version" command to make sure that your installed/alternative JDK is a release compatible with Tomcat 10. If I'm not mistaken, Tomcat 10 is where they switched from JEE to jakarta and it probably needs a fairly recent version of Java as well.

Secondly, I don't think you ever actually posted the log from /opt/tomcat/logs/catalina.out, just what small snippets of it that systemd printed. Tomcat doesn't integrate with systemd logging so I really need the real Tomcat log. Also, take a look at the localhost logs, if they're present. Sometimes the early-startup problems show up there.
 
John Peders
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was a while back, but I'm pretty sure I installed Tomcat using apt/dpkg.

I installed a newer version of Java, know Tomcat 10 needed it:




I've been developing my app for a little while, all the time starting Tomcat with

/opt/tomcat/bin/startup.sh

That seemed to work, although there were errors listed in catalina.out which I ignored, because I saw no effect on my app.

However, I just noticed that I can't log into the browser-based manager app, even though I have the correct credentials as defined in conf/tomcat-users.xml Perhaps this is related to the fact that I can't get Tomcat to run on boot?

Anyway, here's the catalina.out log of a new manual start:



There are other errors I couldn't include as they'd make the post too long, but they have this in common:

org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; The processing instruction target matching "[xX][mM][lL]" is not allowed.


 
Tim Holloway
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah! Yes, it's running Java 17 and I think I can see the problem.

Normally there would be a filename displayed to make sure, but considering where this happened, I'm pretty sure it's the TOMCAT_HOME/conf/server.xml file. It looks like it's damaged.

The error is on line 2 and says that the "<?xml" processing instruction is not valid there. That is correct. XML validators get extremely annoyed when the "<?xml" doesn't start on line 1, column 1. Absolutely nothing is permitted to precede the PI. <br /> <br /> What the first few lines of the server.xml file should look like are: <br /> <br />
 
John Peders
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good call!

However, this is the first few lines of conf/server.xml

<br /> <br /> I'll look for some other xml files with an error on line 2. <br /> <br />
 
John Peders
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ha, there was a blank line at the top of tomcat-users.xml

I guess that's why I wasn't able to log into the manager in the browser, because that file wasn't processed properly.

I won't know if it fixes everything else till I get back to my pi tomorrow.
 
Tim Holloway
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup. When I said "absolutely nothing", I meant absolutely nothing. I've had the old "blank line 1" problem myself a time or 2.

You might want to look at the localhost log files. Possibly the name of the offending XML file will be confirmed there.
 
John Peders
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So removing the blank line at the start of tomcat-users.xml means that if I run "sudo /opt/tomcat/bin/startup.sh" Tomcat fires up just fine, there are no errors at all in the logs, my app runs, and I can get into the manager gui again.

However, I still can't get Tomcat to run on boot!

Here's my unit file, /etc/systemd/system/tomcat.service :



I've tried with no setenv.sh in /opt/tomcat/bin
or variations around:



but I either get nothing new in any log files, or just this one line in catalina.out:

NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED

 
John Peders
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I meant to add this output too:



It's still dying immediately after loading, then telling me I've succeeded. I really haven't!

 
Tim Holloway
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wrong tree.

I don't think you need any setenv.sh for your system. But Tomcat cannot auto-start itself. It has to be started by systemd. And systemd has to be told to auto-start. Otherwise it's going to wait for manual startup.

Try this:


Note: corrected from "systemd" to "systemctl". Sorry.

The "enable" switches on startup-on-boot. The "start" starts it now instead of waiting for reboot.
 
Tim Holloway
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One other thing. Systemd has two primary types of operating modes for services. One is for a service that starts and keeps running. The other is for a service that starts and then almost immediately ends. Because Tomcat's startup and shutdown scripts do not run as long-term processes, it falls under the second category.

I think to make that work properly, you need a "Type=forking" line in your Service section. Otherwise, the status you'll see will reflect the status of the startup script and not Tomcat itself.

Note that to get proper Tomcat status from systemd you'll probably have to setup PIDFile options in both your systemd config  file and on the execution of the Tomcat startup script. I believe you can export the Catalina PIDfile environment variable in setenv.sh
 
John Peders
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I took out the setenv.sh file, did



and added

Type=forking to my Service section

I don't know if I needed all of those things or what, but it's starting on boot just fine now.

Thanks very much for your excellent help and surprising patience!
 
Tim Holloway
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem. Keeps me in practice. Glad I could help!
 
reply
    Bookmark Topic Watch Topic
  • New Topic