Apache启动脚本的建立

[编辑]建立启动脚本
# vi /etc/rc.d/init.d/httpd

将下列代码粘贴到httpd文件中:

#!/bin/bash

# Startup script for the Apache2.0.X Web Server
# Fixed by Comsenz - Nanu ([email protected])

# chkconfig: - 85 15

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

if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi

INITLOG_ARGS=""

apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
prog=httpd
RETVAL=0

start() {
echo -n $"Starting $prog: "
daemon $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
}
reload() {
echo -n $"Reloading $prog: "
killproc $httpd -HUP
RETVAL=$?
echo
}

case "$1" in
start)
start
 ;;
stop)
stop
 ;;
status)
status $httpd
RETVAL=$?
 ;;
restart)
stop
start
 ;;
condrestart)
if [ -f /var/run/httpd.pid ] ; then
stop
start
fi
 ;;
reload)
reload
 ;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
 ;;
*)
echo $"Usage: $prog

{start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac

exit $RETVAL

注意文件中的

apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}

两行,如果您的Apache不是安装在/usr/local/apache2,请根据情况更改以上两行中Apache的路径!

[编辑]授予httpd运行权限
# chmod 755 /etc/rc.d/init.d/httpd

[编辑]将httpd加入系统SysV服务并设置其开机自启动
# chkconfig --add httpd
# chkconfig --level 3 httpd on

这样,今后如需启动、停止、重启Apache就可以用以下方式了:

# service httpd start

# service httpd stop


你可能感兴趣的:(apache,服务器,shell脚本)