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 <amnoje...@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.

Reply via email to