apache加入chkconfig

回复 收藏
第一步:
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

第二步:
vim /etc/init.d/httpd
在第一行#!/bin/sh下增加两行文字
# chkconfig: 35 70 30
# description: Apache

第三步:
保存退出
chkconfig --level 35 httpd on

2015-01-22 20:33 举报
已邀请:
0

l5211314121

赞同来自:

贴个脚本,只把配置文件路径和安装路径稍作修改就行了
#!/bin/bash
#httpdstartup script fot the Apache HTTP Server
#
#
#
#chkconfig: - 85 15  - :is runlevel  85 : 85 is /etc/rc.d/rcN.d/Sfile_name \
#            15 : 15 is/etc/rcN.d/rc/Kfile_name
#description:Apacheis a  World Wide Web server . It is usedto server HTML files and CGI
#
#processname:httpd
#
#config:/etc/httpd/conf/httpd.conf
#pidfile:/var/run/httpd.pid

#Sourcefunctino library.

./etc/rc.d/init.d/functions
if [-f /etc/sysconfig/httpd ]; then
./etc/sysconfig/httpd
fi
HTTPD_LANG=${"C"}
INITLOG_ARGS=""
apacehctl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0



start(){
echo-n  $"Starting $prog: ... "
LANG=$HTTPD_LANGdaemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[$RETVAL = 0 ] && touch ${lockfile}
return$RETVAL
}


stop(){
echo-n $"Stopping $prog: ... "
killproc-p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[$RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

reload(){
echo-n $"Reloading $prog: ... "
if !LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo$"not reloading due to configuration syntax error . "
failure$"not reloading $httpd due to configuration syntax error ."
else
killproc-p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}



#See  how we were called

case"$1" in
start)
start;;
stop)
stop;;
status)
status-p ${pidfile} $httpd
RETVAL=$?;;
restart)
stop
start;;
condrestart)
if [-f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload;;
graceful|htlp|configtest|fullstatus)
$apachectl$@
RETVAL=$?
;;
*)
echo$"Usage : service $prog{start|stop|restart|condrestart|reload|status|fulstatus|graceful|help|configtest}"
exit 1
esac
exit$RETVAL

0

北辰星

赞同来自:

加的那两行是注释掉的??如果是的话,那有差吗?
0

cmzsteven

赞同来自:

权限得改成755吧
chmod 755 /etc/init.d/httpd
0

cmzsteven

赞同来自:

北辰星 发表于 2015-9-22 21:45
加的那两行是注释掉的??如果是的话,那有差吗?

主要是chkconfig那一行,没有那一行,chkconfig不会识别
0

北辰星

赞同来自:

cmzsteven 发表于 2015-9-30 13:13
主要是chkconfig那一行,没有那一行,chkconfig不会识别

可是这两行不都是注释掉的吗?注释了不就没有用了吗?我做实验的时候试了不注释(去掉前面的#),结果就报错了,而注释之后正常,这是为什么呢?
0

cmzsteven

赞同来自:

北辰星 发表于 2015-9-30 15:16
可是这两行不都是注释掉的吗?注释了不就没有用了吗?我做实验的时候试了不注释(去掉前面的#),结果就 ...

第二行不加注释肯定会报错的,因为那只是说明,不是角本本身的内容
第一行应该是chkconfig特殊的格式要求
0

sincethen

赞同来自:

我觉得如果你想在系统重启后仍保持apache运行状态,直接把apachectl的调用加入到你的系统启动文件中就可以了(rc.local)。
0

297168738

赞同来自:

成功是成功了,但是启动和关闭都没提示,很纠结
0

Coohx - 小运维

赞同来自:

# chkconfig: 35 70 30  这几个数字是什么意思
0

Coohx - 小运维

赞同来自:

Coohx 发表于 2016-4-13 19:43
# chkconfig: 35 70 30  这几个数字是什么意思

35 系统运行级别      70 开机时的启动顺序  30 关机时的关闭顺序 两个数字的和是一般是一百 在/etc/rc.d/rc3.d 内会显示这两个值(linux 系统rc.d启动脚本剖析http://blog.csdn.net/cooling88/article/details/51049893)
0

善思致用

赞同来自:

北辰星 发表于 2015-9-22 21:45
加的那两行是注释掉的??如果是的话,那有差吗?

必须要注释的,只是让系统知道启动它的顺序

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: