通哥运维笔记之apache开机启动脚本

apache开机启动脚本

#!/bin/sh

# description: Apache auto start-stop script.

# chkconfig: - 85 15

APACHE_HOME=/usr/local/apache

APACHE_OWNER=root

if [ ! -f "$APACHE_HOME/bin/apachectl" ]

then

    echo "Apache startup: cannot start"

    exit

fi

case "$1" in

    'start')

        su - $APACHE_OWNER -c "$APACHE_HOME/bin/apachectl start"

        ;;

    'stop')

        su - $APACHE_OWNER -c "$APACHE_HOME/bin/apachectl stop"

        ;;

    'restart')

        su - $APACHE_OWNER -c "$APACHE_HOME/bin/apachectl restart"

        ;;

esac


# chmod 755 apache2

# chkconfig --add apache2

# chkconfig --level 345 apache2 on

(chkconfig --add  name:增加一项新的服务。chkconfig确保每个运行级有一项启动(S)或者杀死(K)入口。如有缺少,则会从缺省的init脚本自动建立。   chkconfig --del  name:删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。)

Ok,测试Apache

# service apache2 start

# service apache2 stop

# service apache2 restart

同时reboot OS试一下apache是否开机自动运行了。



tomcat开机启动脚本


#!/bin/sh

case "$1" in

    start)

           /usr/local/tomcat/tomcat6.1/bin/startup.sh

           /usr/local/tomcat/tomcat6.2/bin/startup.sh

           /usr/local/apache/bin/httpd -k start

;;

    stop)

           /usr/local/apache/bin/httpd -k stop

           /usr/local/tomcat/tomcat6.1/bin/shutdown.sh

           /usr/local/tomcat/tomcat6.2/bin/shutdown.sh

;;

   restart)

        $0 stop

        $0 start

;;

*)

     echo "Usage: tomcatAll {start|stop|restart}"

     exit 1

;;

esac



检查服务运行状态



#!/bin/sh

check_services()

{

echo "Check services..."

services=""

if [ -z "`ps -A|grep httpd`" ]

then

services="$services httpd"

fi

}


start_services()

{

echo "Start services..."

for start_services in `echo $services`

do

/etc/init.d/$start_services start

done

echo

}


check_services

echo

echo "Check services succeed!"

echo

start_services

echo

echo "Start services succeed!"

echo


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章