Solved

running apache and tomcat on startup

Posted on 2011-02-28
6
844 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace a tag with sed 2 47
MarkLogic 1 70
unix example issues 18 75
BASH script to modify crontab? 3 50
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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

867 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

22 Experts available now in Live!

Get 1:1 Help Now