Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

running apache and tomcat on startup

Posted on 2011-02-28
6
Medium Priority
?
850 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
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

963 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