Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

running apache and tomcat on startup

Posted on 2011-02-28
6
Medium Priority
?
849 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

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

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 …
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.:
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.
Suggested Courses

670 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