Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Starting Tomcat 10 at bootup

267 views
Skip to first unread message

Amn Ojee Uw

unread,
Nov 26, 2022, 6:50:05 AM11/26/22
to

Hey folks!

The issue :
~~~~~~~

I just installed 'apache-tomcat-10.0.27.tar.gz' in my Debian 11 (stable) box, running OpenjDK 17.0.4, this was done following the recommendation on 'How to Install Apache Tomcat on Debian 11 (Step by Step) '. With the exception of the java installation, I followed the steps up to section 8 where I get this error :

sudo systemctl restart tomcat
Job for tomcat.service failed because the control process exited with error code.
See "systemctl status tomcat.service" and "journalctl -xe" for details.

I followed the recommendation of the error message and I get this : 

systemctl status tomcat.service
● tomcat.service - Tomcat webs servlet container
     Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset>
     Active: activating (auto-restart) (Result: exit-code) since Fri 2022-11-25>
    Process: 86949 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/>
    Process: 86960 ExecStop=/opt/tomcat/bin/shutdown.sh (code=exited, status=1/>
        CPU: 38ms

My Imperfect Solution
~~~~~~~~~~~~~~~

If from the command prompt or a shell script, I run this code sudo '/opt/tomcat/bin/catalina.sh run', Tomcat runs nicely, but it grabs the Terminal, if I close the Terminal, Tomcat just stops working. Obviously not a perfect solution.

I am a newcomer to the Linux world, but in Windows I had the same issue, so I wonder if this is a potential bug.

Please help me resolve this issue or let me know how to report this bug. (This would be my first contribution to the team, so I am rightfully exited).

Thanks in advance.

Charles Curley

unread,
Nov 26, 2022, 9:20:06 AM11/26/22
to
On Sat, 26 Nov 2022 06:40:24 -0500
Amn Ojee Uw <amno...@gmail.com> wrote:

> If from the command prompt or a shell script, I run this code sudo
> '/opt/tomcat/bin/catalina.sh run', Tomcat runs nicely, but it grabs
> the Terminal, if I close the Terminal, Tomcat just stops working.
> Obviously not a perfect solution.

The solution to that is to put the Tomcat instance into the background
by appending an ampersand to the command, like so:

/opt/tomcat/bin/catalina.sh run &

In Windows, the ampersand is unnecessary; programs go into the
background according to the type of program they are. In Unix, one must
specify.

--
Does anybody read signatures any more?

https://charlescurley.com
https://charlescurley.com/blog/

Greg Wooledge

unread,
Nov 26, 2022, 11:50:05 AM11/26/22
to
On Sat, Nov 26, 2022 at 07:07:54AM -0700, Charles Curley wrote:
> On Sat, 26 Nov 2022 06:40:24 -0500
> Amn Ojee Uw <amno...@gmail.com> wrote:
>
> > If from the command prompt or a shell script, I run this code sudo
> > '/opt/tomcat/bin/catalina.sh run', Tomcat runs nicely, but it grabs
> > the Terminal, if I close the Terminal, Tomcat just stops working.
> > Obviously not a perfect solution.
>
> The solution to that is to put the Tomcat instance into the background
> by appending an ampersand to the command, like so:
>
> /opt/tomcat/bin/catalina.sh run &
>
> In Windows, the ampersand is unnecessary; programs go into the
> background according to the type of program they are. In Unix, one must
> specify.

I wish. No, it's the same in Unix. Some programs have been written to
self-background. It was a big thing back in the 1990s. It's horrible
design, and it makes writing init script (or their equivalent) so much
more difficult.

What's you've said here is correct from the point of view of someone
starting the service manually in a shell, without a supervisor. But
it doesn't address the issue of how to write an systemd unit to run
this thing correctly.

I'm not a tomcat user myself, so I can't really give much advice on
writing a unit file for it. All I can give are general tips.

If you HAVE to run a shell script (I'm assuming "catalina.sh" is a shell
script) to start this service, then you're probably not going to be able
to write a normal systemd unit that manages a single process. You're
stuck writing one that manages a FLEET of processes, because that's
what shell scripts do. They create multiple processes, either ephemeral
ones, or persistent ones, or both.

The good news is that systemd was written with the knowledge that such
things still exist in the world, and that a unit file might have to deal
with them.

In systemd.service(5) you'll find a description of the basic types of
services that can be started. The one you want is called "forking".

Type=forking

You'll need to read and understand the systemd documentation *and* the
tomcat documentation, and find a combination of the two that can coexist.
This may mean researching this catalina.sh script and looking for options
to make it do what systemd expects.

More likely it will mean finding a tomcat support mailing list, and asking
the people *there* how they made it start.

I'd be shocked if there isn't already someone out there with a functioning
systemd unit file to start your version of tomcat properly.

Anssi Saari

unread,
Nov 28, 2022, 4:50:05 AM11/28/22
to
Amn Ojee Uw <amno...@gmail.com> writes:

> systemctl status tomcat.service
> ● tomcat.service - Tomcat webs servlet container
> Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset>
> Active: activating (auto-restart) (Result: exit-code) since Fri 2022-11-25>
> Process: 86949 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/>
> Process: 86960 ExecStop=/opt/tomcat/bin/shutdown.sh (code=exited, status=1/>
> CPU: 38ms

So maybe take a look at /opt/tomcat/bin/shutdown.sh to see what might
cause it to exit with an error condition? You could try posting it here
or a link to it.

Jeffrey Walton

unread,
Nov 28, 2022, 8:20:05 AM11/28/22
to
On Sat, Nov 26, 2022 at 11:46 AM Greg Wooledge <gr...@wooledge.org> wrote:
> ...
> In systemd.service(5) you'll find a description of the basic types of
> services that can be started. The one you want is called "forking".
>
> Type=forking
>
> You'll need to read and understand the systemd documentation *and* the
> tomcat documentation, and find a combination of the two that can coexist.
> This may mean researching this catalina.sh script and looking for options
> to make it do what systemd expects.
>
> More likely it will mean finding a tomcat support mailing list, and asking
> the people *there* how they made it start.
>
> I'd be shocked if there isn't already someone out there with a functioning
> systemd unit file to start your version of tomcat properly.

Looking through Tomcat's GitHub, I cannot find a sample systemd unit. Hmm...

But there are lots of sample systemd units out there, like
https://gist.github.com/drmalex07/e6e99dad070a78d5dab24ff3ae032ed1 .
Or more generally,
https://www.google.com/search?q=tomcat+systemd+service+file .

And you were correct - they are forking.

Jeff
0 new messages