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