试析FreeBSD 6.2 的rc脚本系统

2009-05-13 08:01:43来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折


                试析FreeBSD 6.2 的rc脚本系统
杜比环绕声
一、从mysql的启动脚本说起
配置mysql的时候,如果需要启动运行 mysql server,按照 mysql 手册上的说明,需要在 /etc/rc.conf 中,添加一条信息:
    mysql_enable="YES"
这样在重新启动系统的时候,就可以自动运行 mysqlserver.
如果需要运行时,停止 mysqlserver 或者重新启动 mysqlserver,可以使用下面的命令:
停止mysqlserver:          shell>/usr/local/etc/rc.d/mysql-server  stop
重新启动mysqlserver:       shell>/usr/local/etc/rc.d/mysql-server  restart
其实无论是mysqlserver还是apache等系统服务,都可以利用上面提到的参数“stop“,”restart“等进行程序维护
这属于FreeBSD系统rc脚本系统的具体应用。
FreeBSD的rc脚本系统在服务程序的管理上,主要是体现在 /etc/rc.d 和 /usr/local/etc/rc.d 这两个目录下的可执行脚本,系统级别的服务程序的脚本大都安装在 /etc/rc.d目录下,而用户级别的服务程序的脚本都安装在 /usr/local/etc/rc.d 目录下。如 mysql server 在安装的时候会在 /usr/local/etc/rc.d目录下安装一个 mysql-server 的脚本文件。
服务程序的管理,其实运行的就是对应的脚本文件。如上面举例的停止服务,重新启动服务,运行的都是mysql-server脚本。
二、mysql-server 启动脚本的说明
下面的脚本代码是freebsd 6.2中mysqlserver 5.0的启动脚本。具体的功能在脚本代码中注释!
#!/bin/sh     
#
# $FreeBSD: ports/databases/mysql50-server/files/mysql-server.sh.in,v 1.3 2006/03/07 16:25:00 ale Exp $
#
#下面这部分文本描述了可以在rc.conf中设置、添加的启动条目,用来控制mysqlserver启动的一些具体细节。
# PROVIDE: mysql
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable mysql:
# mysql_enable (bool):    Set to "NO" by default.
#            Set it to "YES" to enable MySQL.
# mysql_limits (bool):    Set to "NO" by default.
#            Set it to yes to run `limits -e -U mysql`
#            just before mysql starts.
# mysql_dbdir (str):    Default to "/var/db/mysql"
#            Base database directory.
# mysql_args (str):    Custom additional arguments to be passed
#            to mysqld_safe (default empty).
#
# 下面的这行代码非常重要,作用是在mysql-server的脚本代码中插入 /etc/rc.subr 文件的代码!
# 在 /etc/rc.subr 文件中,提供了 mysql-server 调用的函数的实现,也提供了很多rc脚本系统中用到的函数。
# mysql-server 中能够使用的 start,stop,restart,rcvar等参数的具体运作,也是在 /etc/rc.subr 中提供的。
. /etc/rc.subr
# 在 /etc/rc.subr 中,首先运行一些初始化命令,跟踪运行,执行了以下命令:
    if [ -z "${_rc_subr_loaded}" ]; then

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:FREE BSD SSH

下一篇:关于网络的七个致命误解