How to automatically restart Apache on system reboot time ?

Saturday, February 28, 2015

How to automatically restart Apache on system reboot time ?

To Start Apache at Boot Time, need to do below process. The Apache server is started as root because it uses port 80 (lower than 1024) but it spawns processes that run as "nobody".

Save the following script as /etc/init/apache. it will automatically be read and run at boot time. Check the log files if it does not start properly.

Make a link to it from /etc/rc5.d such as:
cd /etc/rc5.d
sudo ln -s ../init.d/apache S72apache

----------------------------  /etc/init.d/apache  ------------------------
#!/bin/bash
#
# apache        
#
# chkconfig: 
# description:  Start up the Apache web server.

# Source function library.
. /etc/init.d/functions


RETVAL=$?
APACHE_HOME="/usr/apps/apache/apache"

case "$1" in
 start)
 if [ -f $APACHE_HOME/bin/apachectl ]; then
     echo $"Starting Apache"
        $APACHE_HOME/bin/apachectl start
    fi
 ;;
 stop)
 if [ -f $APACHE_HOME/bin/apachectl ]; then
     echo $"Stopping Apache"
        $APACHE_HOME/bin/apachectl stop
    fi
  ;;
 *)
  echo $"Usage: $0 {start|stop}"
 exit 1
 ;;
esac

exit $RETVAL
-----------------------  end of /etc/init.d/apache  ----------------------

Read more...

How to automatically restart Tomcat on system reboot time ?

How to automatically restart Tomcat on system reboot time ?

There are 2 method:-

Method 1. Create the init script in /etc/init.d/tomcat with following lines :-

#!/bin/sh
# chkconfig: - 80 20
# Created by: USer
# Purpose: Start or stop the Tomcat service.
# Check the path of Tomcat and set enviorment variables as follows in the .bashrc profile
# chkconfig: 345 99 01
#chkconfig: 2345 50 70
# export CATALINA_HOME="/usr/local/tomcat7/apache-tomcat-7.0.37"
# export CATALINA_BASE="/usr/local/tomcat7/apache-tomcat-7.0.37"
# export JAVA_HOME="/usr/local/java/jdk1.7.0_17"
#export JAVA_HOME="/usr/java/jdk1.5.0_15"
export JAVA_HOME="/usr/java/jdk1.6.0_25"
case $1 in
start)
cd /usr/local/tomcat/bin/
./startup.sh
;;
stop)
cd /usr/local/tomcat/bin/
./shutdown.sh
;;
restart)
cd /usr/local/tomcat/bin/
./shutdown.sh
cd /usr/local/tomcat/bin/
./startup.sh
;;
esac
exit 0

--------------------

Change its permissions and add the correct symlinks automatically:-
chmod 755 /etc/init.d/tomcat7
update-rc.d tomcat7 defaults


Method 2:-
user should be valid "tomcat" and has rw permissions in the $CATALINA_HOME/conf and $CATALINA_HOME/logs directories. and $JAVA_HOME shpuld be proper set. You will start Tomcat as user "tomcat" to avoid running it as root.

Save the following script as /etc/init.d/tomcat . it will automatically be read and run at boot time. Check the log files if it does not start properly.

Make a link to it from /etc/rc5.d such as:

cd /etc/rc5.d
sudo ln -s ../init.d/tomcat S71tomcat

----------------------------  /etc/init.d/tomcat  ------------------------
#!/bin/bash
#
# tomcat      
#
# chkconfig:
# description: Start up the Tomcat servlet engine.

# Source function library.
. /etc/init.d/functions


RETVAL=$?
CATALINA_HOME="/usr/local/tomcat/jakarta-tomcat-6"

case "$1" in
 start)
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
   echo $"Starting Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/startup.sh
        fi
;;
 stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
   echo $"Stopping Tomcat"
            /bin/su tomcat $CATALINA_HOME/bin/shutdown.sh
        fi
  ;;
 *)
  echo $"Usage: $0 {start|stop}"
exit 1
;;
esac

exit $RETVAL
-----------------------  end of /etc/init.d/tomcat  ----------------------











Read more...

About This Blog

Lorem Ipsum

  © Copyright 2009 Linux-HelpLine.Blogspot.com

Back to TOP