Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-17-2011, 02:46 AM
|
#1
|
Member
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798
Rep:
|
tomcat startup script
I am looking for a tomcat start up script on a Ubuntu machine.
My Ubuntu is 10.04 server.
The tomcat is 5.5.30.
It is in /opt/apache-tomcat-5.5.31
I tried a script here
Code:
#!/bin/bash
#
# tomcat
#
# chkconfig:
# description: Start up the Tomcat servlet engine.
# Source function library.
. /etc/init.d/functions
RETVAL=$?
CATALINA_HOME="/opt/apache-tomcat-5.5.31"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
but it did not worked after a reboot.
Last edited by tkmsr; 02-17-2011 at 02:57 AM.
|
|
|
02-17-2011, 03:12 AM
|
#2
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
|
Hi,
Does it work when you run it directly, like /etc/init.d/tomcat?
If it does, you can run:
Code:
sudo update-rc.d tomcat defaults
to create the needed symlinks in the various runlevels
Regards
|
|
|
02-17-2011, 03:28 AM
|
#3
|
Member
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798
Original Poster
Rep:
|
Ok When I run it directly as you mentioned
/etc/init.d/tomcat
then I get error
Quote:
./tomcat: line 9: /etc/init.d/functions: No such file or directory
Usage: ./tomcat {start|stop}
|
Ok I realized the mistake in the line above in rest of the init scripts on my server the line for init-functions is
Quote:
. /lib/lsb/init-functions
|
So now I changed the script to
Code:
. /lib/lsb/init-functions
RETVAL=$?
CATALINA_HOME="/opt/apache-tomcat-5.5.31"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
and now I executed /etc/init.d/tomcat
the problem I saw basically now is that my application which is currently here
/opt/apache-tomcat-5.5.31
is now in accessible.
I am using tomcat 5.5
and to start each time that
I do an ssh and then cd /opt/apache-tomcat-5.5.31/bin
and then type startup.sh then it does start.
But not when this script is in a format as above.
Last edited by tkmsr; 02-17-2011 at 03:59 AM.
|
|
|
02-17-2011, 04:09 AM
|
#4
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
|
The default runlevels to start services are 2 3 4 5, so I guess that's why it isn't starting on rcS.
Quote:
Only things that need to be run once to get the system into a consistent state are to be run. The rcS.d directory is NOT meant to replace rc.local. One should not start daemons in this runlevel unless absolutely necessary. Eg, NFS might need the portmapper, so it is OK to start it early in the bootprocess. But this is not the time to start the squid proxy server.
|
|
|
|
02-17-2011, 05:16 AM
|
#5
|
Member
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798
Original Poster
Rep:
|
Ok by the time I saw your message I understood the problem and had edited my Tomcat script is basically wrong.
If you notice
Quote:
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
fi
|
that means if file $CATALINA_HOME/bin/startup.sh exists then
echo $"Starting Tomcat"
thats it.So it was not starting.Any how I modified it more and now it works correctly.
Quote:
#!/bin/bash
#
# tomcat
#
# chkconfig:
# description: Start up the Tomcat servlet engine.
# Source function library.
. /lib/lsb/init-functions
RETVAL=$?
CATALINA_HOME="/opt/apache-tomcat-5.5.31"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
/opt/apache-tomcat-5.5.31/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
/opt/apache-tomcat-5.5.31/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
|
So now the scripts does work fine.
I checked and update-rc.d tomcat defaults
Now I reboot the machine but after a reboot I did not got the application which was hosted on Tomcat instance.
What I observe is for my application to work when the system boots up I again login via ssh and
Code:
cd /opt/apache-tomcat-5.5.31/bin#
./startup.sh
and then it works.
So this time the script is also fine so why is this not working?
|
|
|
02-17-2011, 05:55 AM
|
#6
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
|
You mean it works when you run:
Code:
/etc/init.d/tomcat start
but not at system startup?
I guess you need to define also JAVA_HOME in your script, because I don't think it's defined at boot time.
|
|
|
02-17-2011, 06:21 AM
|
#7
|
Member
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798
Original Poster
Rep:
|
I defined JAVA_HOME as you mention JAVA_HOME but still on boot it failed to start I had to manually go and start by $CATALINA_HOME/bin/startup.sh
Last edited by tkmsr; 02-17-2011 at 06:46 AM.
|
|
|
02-17-2011, 07:12 AM
|
#8
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
|
Does it starts when you run:
Code:
/etc/init.d/tomcat start
If it does, then it should also start from /etc/rc2.d/S20tomcat.
And why do you need to cd into $CATALINA_HOME? What happens if you run
Code:
/opt/apache-tomcat-5.5.31/bin/startup.sh
You should also check the startup logs to see if you find the reason tomcat is not starting.
BTW you can put the above command in /etc/rc.local as it's the last script executed on boot (and of course remove tomcat from rc.d)
Code:
sudo update-rc.d tomcat remove
|
|
|
02-17-2011, 07:30 AM
|
#9
|
Member
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798
Original Poster
Rep:
|
Quote:
Originally Posted by bathory
Does it starts when you run:
Code:
/etc/init.d/tomcat start
|
Yes it runs.
Quote:
Originally Posted by bathory
If it does, then it should also start from /etc/rc2.d/S20tomcat.
|
This does not happen.
Quote:
Originally Posted by bathory
And why do you need to cd into $CATALINA_HOME? What happens if you run
Code:
/opt/apache-tomcat-5.5.31/bin/startup.sh
|
This also works.
Quote:
Originally Posted by bathory
You should also check the startup logs to see if you find the reason tomcat is not starting.
|
I have following log files in /var/log
Quote:
apache2 auth.log.3.gz daemon.log.2.gz dmesg.0 faillog lastlog mail.log.2.gz mysql.err pycentral.log ufw.log
apparmor auth.log.4.gz daemon.log.3.gz dmesg.1.gz fontconfig.log lpr.log mail.log.3.gz mysql.log syslog unattended-upgrades
apt boot daemon.log.4.gz dmesg.2.gz fsck mail.err mail.log.4.gz mysql.log.1.gz syslog.1 user.log
aptitude boot.log debug dmesg.3.gz installer mail.info mail.warn mysql.log.2.gz syslog.2.gz user.log.1
aptitude.1.gz btmp debug.1 dmesg.4.gz kern.log mail.info.1 messages mysql.log.3.gz syslog.3.gz user.log.2.gz
aptitude.2.gz btmp.1 debug.2.gz dpkg.log kern.log.1 mail.info.2.gz messages.1 mysql.log.4.gz syslog.4.gz user.log.3.gz
aptitude.3.gz ConsoleKit debug.3.gz dpkg.log.1 kern.log.2.gz mail.info.3.gz messages.2.gz mysql.log.5.gz syslog.5.gz user.log.4.gz
auth.log cron-apt debug.4.gz dpkg.log.2.gz kern.log.3.gz mail.info.4.gz messages.3.gz mysql.log.6.gz syslog.6.gz wtmp
auth.log.1 daemon.log dist-upgrade dpkg.log.3.gz kern.log.4.gz mail.log messages.4.gz mysql.log.7.gz syslog.7.gz wtmp.1
auth.log.2.gz daemon.log.1 dmesg dpkg.log.4.gz landscape mail.log.1 mysql news udev
|
Other than this
I have in
/opt/apache-tomcat-5.5.31/logs
Quote:
admin.2011-02-01.log catalina.2011-02-01.log catalina.out host-manager.2011-02-17.log localhost.2011-02-17.log manager.2011-02-17.log
admin.2011-02-17.log catalina.2011-02-17.log host-manager.2011-02-01.log localhost.2011-02-01.log manager.2011-02-01.log
|
but the logs here are all blank.
Which one you are pointing to.
Quote:
Originally Posted by bathory
BTW you can put the above command in /etc/rc.local as it's the last script executed on boot (and of course remove tomcat from rc.d)
Code:
sudo update-rc.d tomcat remove
|
Ok I will try this also.
|
|
|
02-17-2011, 07:54 AM
|
#10
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
|
I guess the startup logs are written in /var/log/boot /var/log/syslog /var/log/messages and /var/log/daemon. tomcat logs are useless here, eventhough at least catalina.out shouldn't be blank.
Quote:
Quote:
Originally Posted by bathory View Post
BTW you can put the above command in /etc/rc.local as it's the last script executed on boot (and of course remove tomcat from rc.d)
Code:
sudo update-rc.d tomcat remove
Ok I will try this also.
|
Do it as a last resort. It's not bad to use /etc/rc.local (in fact I use it to start almost everything in Slackware), but out of curiosity I would like to see why the other way does not work.
|
|
|
02-17-2011, 09:02 AM
|
#11
|
Member
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798
Original Poster
Rep:
|
Ok file /var/log/boot.log has following
Quote:
Starting Tomcat
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
* Starting web server apache2 ^[[80G ^M^[[74G[ OK ]
|
but this is not correct as JAVA_HOME was defined in script.
daemon.log does not have any thing useful if you want to see here it is http://pastebin.com/mf8SYLnt
even I want to understand why it does not work.
|
|
|
02-17-2011, 09:32 AM
|
#12
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
|
It doesn't work because somehow JAVA_HOME is unset.
You can set the JAVA_HOME in /opt/apache-tomcat-5.5.31/bin/catalina.sh, so it's always set.
|
|
|
02-18-2011, 10:37 AM
|
#13
|
Member
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798
Original Poster
Rep:
|
Well sorry for the delayed reply I have very strong fever here.I did try JAVA_HOME in catalina.sh but after a reboot it did not worked.
|
|
|
02-18-2011, 01:06 PM
|
#14
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
|
Hope you being well.
Are you sure it didn't work. Maybe you see that JAVA_HOME is not set, because it's define inside the catalina.sh script, but tomcat is running. In ubuntu it's something like: JAVA_HOME=/usr/lib/jvm/java-6-sun
|
|
|
02-21-2011, 06:31 PM
|
#15
|
Member
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798
Original Poster
Rep:
|
I am sure it did not worked because I had to ssh into the machine and manually do
Quote:
/opt/apache-tomcat-5.5.31/bin/startup.sh
|
then only things started working.
Ok I just checked things are working at reboot.
Here is the new script
Quote:
#!/bin/bash
#
# tomcat
#
# chkconfig:
# description: Start up the Tomcat servlet engine.
# Source function library.
. /lib/lsb/init-functions
RETVAL=$?
export CATALINA_HOME="/opt/apache-tomcat-5.5.31"
export JAVA_HOME="/usr/lib/jvm/java-6-sun"
#export JAVA_OPTS='-server -Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m -XX:NewSize=192m -XX:MaxNewSize=384m -Djava.awt.headless=true -Dhttp.agent=Sakai -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false -Dsun.lang.ClassLoader.allowArraySyntax=true'
#export PATH=PATH:$JAVA_HOME/bin
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
/opt/apache-tomcat-5.5.31/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
/opt/apache-tomcat-5.5.31/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
|
While testing I had removed the links
Quote:
update-rc.d tomcat remove
|
and had forgotten to link.
So after each reboot it obviously was not working.But I also found one problem in previous scripts
I had used at some places this as follows
Quote:
export CATALINA_HOME="/opt/apache-tomcat-5.5.31/"
|
but it should be as note the missing slash at end.
Quote:
export CATALINA_HOME="/opt/apache-tomcat-5.5.31"
|
Now after each reboot it is working fine.
Thanks for your help again.
Last edited by tkmsr; 02-21-2011 at 07:22 PM.
|
|
|
All times are GMT -5. The time now is 04:26 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|