LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-17-2011, 02:46 AM   #1
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Rep: Reputation: 39
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.
 
Old 02-17-2011, 03:12 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
Blog Entries: 1

Rep: Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073
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
 
Old 02-17-2011, 03:28 AM   #3
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
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.
 
Old 02-17-2011, 04:09 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
Blog Entries: 1

Rep: Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073
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.
 
Old 02-17-2011, 05:16 AM   #5
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
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
Quote:
/etc/init.d/tomcat start
and
Quote:
/etc/init.d/tomcat stop
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?
 
Old 02-17-2011, 05:55 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
Blog Entries: 1

Rep: Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073
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.
 
Old 02-17-2011, 06:21 AM   #7
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
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.
 
Old 02-17-2011, 07:12 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
Blog Entries: 1

Rep: Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073
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
 
Old 02-17-2011, 07:30 AM   #9
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by bathory View Post
Does it starts when you run:
Code:
/etc/init.d/tomcat start
Yes it runs.
Quote:
Originally Posted by bathory View Post
If it does, then it should also start from /etc/rc2.d/S20tomcat.
This does not happen.
Quote:
Originally Posted by bathory View Post
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 View Post
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 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.
 
Old 02-17-2011, 07:54 AM   #10
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
Blog Entries: 1

Rep: Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073
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.
 
Old 02-17-2011, 09:02 AM   #11
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
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.
 
Old 02-17-2011, 09:32 AM   #12
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
Blog Entries: 1

Rep: Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073
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.
 
Old 02-18-2011, 10:37 AM   #13
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
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.
 
Old 02-18-2011, 01:06 PM   #14
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,218
Blog Entries: 1

Rep: Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073Reputation: 2073
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
 
Old 02-21-2011, 06:31 PM   #15
tkmsr
Member
 
Registered: Oct 2006
Distribution: Ubuntu,Open Suse,Debian,Mac OS X
Posts: 798

Original Poster
Rep: Reputation: 39
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tomcat 5 Startup warnings tatacalu Linux - Server 1 12-27-2006 11:33 AM
how to get Tomcat to run on startup? TrevorS Slackware 8 09-19-2006 11:24 PM
tomcat startup on boot malbery Linux - Software 3 01-27-2005 05:10 PM
startup Tomcat 5.5.4 in Fedora 2 treotan Linux - Newbie 1 12-03-2004 10:46 PM
TOMCAT init script not working on startup -- tomcat 4.x / Mandrake Linux 8.0 jmartinph Mandriva 0 03-08-2004 02:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration