I will to install tomcat on Opensuse 42.2 64 bits.
I would like to know if i can use this script and if is right save it as tomcat in /etc/init.d . Is there some thing to do? I did read some blogs about Tomcat as service to start with boot.
Follow the script
“/etc/init.d” folder: #!/bin/bash
tomcat
chkconfig:
description: Start up the Tomcat servlet engine.
Source function library.
. /etc/init.d/functions
RETVAL=$?
CATALINA_HOME="/path/to/tomcat"
case “$1” in
start)
if -f $CATALINA_HOME/bin/startup.sh ];
then
echo $“Starting Tomcat”
/bin/su -s /bin/bash tomcat $CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $“Stopping Tomcat”
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $“Usage: $0 {start|stop}”
exit 1
;;
esac
exit $RETVAL
### BEGIN INIT INFO
# Provides:
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Short-Description:
# Description:
# ........
### END INIT INFO
which means that none of the tools (including YaST > System > System services) can be used to enable/disable it.
But more important is that openSUSE already for some time uses Systemd and not SysVinit for managing services. And while Systemd still does backward support for the old init.d/rcN.d constructs, I doubt that it can do so without a proper INIT INFO section.
So best is to create/find a Systemd unit for your product or add a correct INIT INFO section. to the script.
(BTW, I did not inspect the script for other potential problems with openSUSE).
Do you think is not possible run this script in opensuse 42?
I did read some blogs with various kind of scripts
And I do not know what is secure to use in opesuse to have not problems
I haven’t installed Tomcat for quite awhile,
But for starters it looks like your script does really basic stuff like stop/start.
As others have described, nowadays the standard systemd commands support that and much more so I’d recommend when you install Tomcat from the OSS that you do just that first… inspect the Tomcat Unit file to see what is configured there.
I recommend you find a quick overview of systemd somewhere and at least skim it. For starters, systemd is a sub-system replacement that is gradually replacing all init.d commands and much more. Benefits include standardizing on common command syntax that can be applied across all subsystems instead of having to learn syntax for each one (example has been numerous ways in the past to set up, manage and maintain different services). A starting point is to inspect the “help” and MAN pages for systemctl, to a large extent starting from this one place you can investigate quite a bit since systemd is largely self-documented
systemctl --help
I don’t know if defining Java environmental variables is still required (specifically $CATALINA).
That’s something to inspect in the Unit file and what might exist in a profile.local or in the directory /etc/profile.d/
On 07/13/2017 09:26 AM, tsu2 wrote:
>
> I haven’t installed Tomcat for quite awhile,
> But for starters it looks like your script does really basic stuff like
> stop/start.
> As others have described, nowadays the standard systemd commands support
> that and much more so I’d recommend when you install Tomcat from the OSS
> that you do just that first… inspect the Tomcat Unit file to see what
> is configured there.
>
> I recommend you find a quick overview of systemd somewhere and at least
> skim it. For starters, systemd is a sub-system replacement that is
> gradually replacing all init.d commands and much more. Benefits include
> standardizing on common command syntax that can be applied across all
> subsystems instead of having to learn syntax for each one (example has
> been numerous ways in the past to set up, manage and maintain different
> services). A starting point is to inspect the “help” and MAN pages for
> systemctl, to a large extent starting from this one place you can
> investigate quite a bit since systemd is largely self-documented
>
> Code:
> --------------------
> systemctl --help
> --------------------
>
And keep in mind that systemctl is tab aware:
code:
systemctl start <tab><tab>
will show all of the system services available to start.
–
Ken
linux since 1994
S.u.S.E./openSUSE since 1996
Instead of so much guessing,
I’d ask you to post the details of your tomcat capplication, where it is from and if you are following any guides to deploy that application, the URL to that guide.
tomcat 8.0.44 is installed and running at:
/usr/sistemasequiplano/sistemasequiplanoweb/tomcat
It is running ok
But, I would like that tomcat will be a service system that start on boot and can start/stop by commands: service tomcat start/stop
I did read many blogs and other forums but, there are many kinds to do tomcat service. I need to do one that really works without system problems because tomcat is on a production machine.
On 07/14/2017 11:06 AM, doguibnu wrote:
>
> Hello!
>
> tomcat 8.0.44 is installed and running at:
> /usr/sistemasequiplano/sistemasequiplanoweb/tomcat
>
> It is running ok
>
> But, I would like that tomcat will be a service system that start on
> boot and can start/stop by commands: service tomcat start/stop
>
And what is wrong with:
code:
systemctl start/stop tomcat
–
Ken
linux since 1994
S.u.S.E./openSUSE since 1996
First, you should verify that a Tomcat Unit file exists (that’s the systemd configuration file that systemctl invokes)
The following lists all system Unit files on your machine
ls /usr/lib/systemd/system/
If you have a file in the above location named tomcat.service, you can open it in your text editor of choice and inspect what happens when you invoke with a “systemctl start tomcat.service” command.
You can always check the status of your app/service by invoking the “status” option like in the following
systemctl status tomcat.service
You’ll notice that the above command will return information which is very similar to what you saw inspecting the Unit file with a text editor, except that you’ll also see the current runtime status, if it’s “active, loaded” it’s running.
The “status” will also display whether the app is “enabled” or “disabled” which is whether your app will start up on boot or not. Change it to “enabled” if necessary with the following command to enable the app/service to start on boot
systemctl enable tomcat.service
For more info on systemd commands and architecture, numerous online guides can walk you through beginner steps and of course detailed info can be found int he MAN pages.
Edit /etc/tomcat/tomcat.conf , find and change; CATALINA_HOME= and CATALINA_BASE= to point to your Tomcat installation, customize JAVA_OPTS= if necessary.
Make sure tomcat owns or has suitable permissions to your webapps directory in your tomcat installation.
Enjoy using systemctl status tomcat, restart and other systemctl commands.
Hacking together your own startup script is plain bad, as is creating random directories under /usr/, either put it in /opt or /usr/local/
I have a VM with opensuse 42.2 64 bits to do tests
So, reading some pages I can do tomcat systemctl script that works
But, I want to know if secure use it
Follow the script on my scenario:
But Pay attention please:
There is 2 Lines commented ( # ) because the original tomcat (production machine) have JAVA_OPTS configured in catalina.sh allright.
My doubt:
Need I put JAVA_OPTS in this script - tomcat.service
I create the file tomcat.pid because no has it
Still I can not do a good tomcat script systemd that works perfect.
When I do the command: systemctl enable tomcat the system gives me errors. The same when I go to the GUI opensuse service and try select enable tomcat.
I do not what to do to fix it.
Installed tomcat by installing the LAMP pattern and the tomcat package plus the tomcat sample apps package just to verify if tomcat is working or not
zypper in patterns-openSUSE-lamp_server tomcat tomcat-webapps
I then started the apache2 and tomcat apps with the following commands (By default all newly installed apps in openSUSE are in “stopped,” not running state).
systemctl start apache2
systemctl start tomcat
Determined package contents of “tomcat-webapps” to inspect contents. Found that a sample app exists at /srv/www/tomcat/sample/
rpm -ql tomcat-webapps
Set up the newly installed Apache with a virtualhost pointing to the tomcat sample app using the YaST http-server module.
Restarted apache2 with the following command (may not be needed, closing the YaST http-server module saving changes should have restarted automatically)
systemctl restart apache2.service
Opened a web browser to the URL specified by the virtual host I set up, displaying the tomcat sample app (It has a graphic cat compared to the default Apache test page which just says “It Works!”)
You can inspect the contents of the tomcat config file at /etc/tomcat/tomcat.config
In it, you’ll see that is where you can set all your default tomcat environment settings including $CATALINA, java, java options and more. The stanzas in your custom tomcat Unit file which I’ve highlighted in orange are all configured in the tomcat.config file.
So, , if you installed tomcat from openSUSE, it should already be created for you.
Finally, now that it’s verified working the apache2 and tomcat services can be set to auto start on boot with the following commands
Install SUSE’s tomcat package and edit /etc/tomcat/tomcat.conf to point to your own tomcat installation - then the normal startup scripts will work just fine. Your *.sh files in the tomcat/bin will have to have execute flag set for it to work as well.