Solved

running apache and tomcat on startup

Posted on 2011-02-28
6
847 Views
Last Modified: 2012-05-11
Hi,
I've installed apache and tomcat servers on ubuntu on amazon ec2. Now every time i run instance i need to manually run following commands:
sh /usr/local/tomcat/apache-tomcat-7.0.8/bin/startup.sh
/etc/init.d/apache2 start

is there a way to run those commands every time the system starts?
0
Comment
Question by:static86
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:larsrohr
ID: 35004758
You can create a startup script for tomcat, and configure both startup scripts to start the services automatically.

As root, edit /etc/init.d/tomcat, with a script like the attached code (you may need to edit this to suit your needs).

Then do:
  chmod 755 /etc/init.d/tomcat
  update-rc.d apache2 defaults
  update-rc.d tomcat defaults


#!/bin/sh
#
# /etc/init.d/tomcat -- startup script for Tomcat servlet engine
#
### BEGIN INIT INFO
# Provides:          tomcat
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Tomcat.
# Description:       Start the Tomcat servlet engine.
### END INIT INFO

PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=tomcat7
DESC="Tomcat servlet engine"

# Make sure tomcat is started with system locale
if [ -r /etc/default/locale ]; then
        . /etc/default/locale
        export LANG
fi

. /lib/lsb/init-functions

# You may need to set JAVA_HOME to the correct value:
#export JAVA_HOME=/usr/lib/jvm/java-6-sun 

case "$1" in
  start)
        log_begin_msg "Starting $DESC" "$NAME"
        sh /usr/local/tomcat/apache-tomcat-7.0.8/bin/startup.sh
        ;;
  stop)
        log_daemon_msg "Stopping $DESC" "$NAME"
        sh /usr/local/tomcat/apache-tomcat-7.0.8/bin/shutdown.sh
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  *)
        log_success_msg "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0

Open in new window

0
 

Author Comment

by:static86
ID: 35029272
thanks!, tomcat starts after reboot, but with apache2 I got following:
System start/stop links for /etc/init.d/apache2 already exist.
Any ideas?
0
 
LVL 12

Expert Comment

by:larsrohr
ID: 35030160
The "update-rc.d apache2 defaults" command just puts those start/stop links into the right places, so the message you got indicates those links were already there.

So does apache2 actually start after reboot?  If not, check out /var/log/apache2/error.log to see if it tried to start but ran into problems.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:static86
ID: 35030650
I don't have any new entries in error.log afrer rebooting:/, so it does not even tried to start?
0
 
LVL 12

Accepted Solution

by:
larsrohr earned 500 total points
ID: 35031802
Hmm.  So the start/stop links are in place, but apache2 is not running after reboot?

This is a bit of a heavy-handed approach, but you could edit /etc/rc.local, and just before the last line ("exit 0"), insert this line:

/etc/init.d/apache2 restart
0
 

Author Closing Comment

by:static86
ID: 35032228
thanks!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question