Solved

running apache and tomcat on startup

Posted on 2011-02-28
6
843 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:static86
Comment Utility
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
Comment Utility
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
Comment Utility
thanks!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now