LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1247|回复: 2

openbsd /etc/rc文件导读:

[复制链接]
发表于 2004-6-3 16:40:52 | 显示全部楼层 |阅读模式
/etc/rc文件导读

前言:
openbsd启动时执行/etc/rc文件, 检查挂载文件系统, 启动系统上如httpd, ftpd, named等服务, 因此我们有空时读读这个shell脚本文件对启动系统时出现的各类信息会有一个明确的了解.

基础知识:

shell编程的知识:
首先, 我们来说说if条件结构
在sh编程中:

  1. if command; then
  2.   some commands;
  3. fi
复制代码

第一个command语句用来测试值, 如果为真, 则执行下面的some commands; 如果为假, 跳过if语句块.

test命令常与if条件语句一起使用, test命令有字符串判断, 逻辑判断, 整数判断,文件判断等, 我们在这里只说说下面/etc/rc文件中用的test测试:

-f /var/somefile 测试后面跟着的参数是否是一个文件,

-d /var/dir 测试后面跟着的参数是否是一个目录,

!-f /var/somefile 对-f /var/somefile的结果取反。

-s /var/file 测试-s后面跟着的文件是否为一个非空文件

下面几个命令用于整数判断: -eq 等于, -ne 不等于, -gt 大于, -ge 大于等于, -lt小于, -le小于等于.

我们回来说说实例:
if [ $1x = shutdownx ]; then
判断第一个参数是否等于shutdown。

if [ “X${pf}” != X”NO” ]; then
这个用来测试从/etc/rc.conf里传递来来的pf参数是否等于NO, 如果不等于NO, 则执行if语句块中的命令。

在这里,为何在test的比较两边都加上一个X或x呢? 这是为了保证即使左边参数为空, 操作符两边仍然有占位符。 比如当你在/etc/rc.conf里删除了pf这一行, 如果在这里不放一个X在前面, 测试两边都变成为空, 这时test命令就会失败。因此我们在看脚本时自已在脑海中去掉这个X就可以了。

If [ X${nfs_server} = X”YES” –a –s /etc/exports –a \
   `sed –e ‘/^#/d’ < /etc/exports | wc –l ` -ne 0 ]; then
这里重点是-a这个参数, 这是一个逻辑判断,判断前面的X${nfs_server} = X”YES”是否为真, 不为真是马上退出判断, 返回假; 然后再判断–s /etc/exports是否为真,同上一样, 不为真时马上退出判断; 最后再判断`sed –e ‘/^#/d’ < /etc/exports | wc –l ` -ne 0 是否为真, 只有这三个表达式都为真是这个中括号的结果才为真, 有一个为假都是假。具体命令分析就不说明了!

其它两个控制结构是:

  1. case variable in
  2. value1)
  3.        command
  4.                 ;;
  5. value2)
  6.       command
  7.                 ;;
  8. *)
  9.                 command
  10.                 ;;
  11. esac

  12. for variable in var_list
  13. do
  14.     commands
  15. done
复制代码

我就不详细说明了, 具体更多的情况请有兴趣的朋友们参看sh编程。


另一个要提一提的是: >/dev/null 2 >&1  这个语句的意思是将标准输出stdout和标准错误stderr重定向到/dev/null.

下面来简单看看/etc/rc文件:

  1. #        $OpenBSD: rc,v 1.241 2004/03/22 15:02:35 cedric Exp $

  2. # System startup script run by init on autoboot
  3. # or after single-user.
  4. # Output and error are redirected to console by init,
  5. # and the console is the controlling terminal.

  6. # Subroutines (have to come first).

  7. # Strip comments (and leading/trailing whitespace if IFS is set)
  8. # from a file and spew to stdout

  9. 定义一个shel函数:
  10. stripcom() {
  11.         local _file="$1"
  12.         local _line

  13.         {
  14.                 while read _line ; do
  15.                         _line=${_line%%#*}                # strip comments
  16.                         test -z "$_line" && continue
  17.                         echo $_line
  18.                 done
  19.         } < $_file
  20. }

  21. # End subroutines

  22. stty status '^T'

  23. # Set shell to ignore SIGINT (2), but not children;
  24. # shell catches SIGQUIT (3) and returns to single user after fsck.

  25. 忽略信号2, 3
  26. trap : 2
  27. trap : 3        # shouldn't be needed

  28. 设置根目录, 和命令的查找路径:
  29. HOME=/; export HOME
  30. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  31. export PATH

  32. 查看命令是否等于shutdown 如果是, 执行下面的语句块:

  33. if [ $1x = shutdownx ]; then
  34.         dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 >/dev/null 2>&1
  35.         chmod 600 /var/db/host.random >/dev/null 2>&1
  36.         if [ $? -eq 0 -a -f /etc/rc.shutdown ]; then
  37.                 echo /etc/rc.shutdown in progress...
  38.                 . /etc/rc.shutdown
  39.                 echo /etc/rc.shutdown complete.
  40.                 if [ "X${powerdown}" = X"YES" ]; then
  41.                         exit 2
  42.                 fi

  43.                 # bring carp interfaces down gracefully
  44.                 for hn in /etc/hostname.carp[0-9]*; do
  45.                         # Strip off /etc/hostname. prefix
  46.                         if=${hn#/etc/hostname.}
  47.                         test "$if" = "carp[0-9]*" && continue

  48.                         ifconfig $if down
  49.                 done
  50.         else
  51.                 echo single user: not running /etc/rc.shutdown
  52.         fi
  53.         exit 0
  54. fi

  55. 读取/etc/ccd.conf, 设置ccfconf
  56. # Configure ccd devices.
  57. if [ -f /etc/ccd.conf ]; then
  58.         ccdconfig -C
  59. fi

  60. 设置raid
  61. # Configure raid devices.
  62. for dev in 0 1 2 3; do
  63.         if [ -f /etc/raid$dev.conf ]; then
  64.                 raidctl -c /etc/raid$dev.conf raid$dev
  65.         fi
  66. done

  67. # Check parity on raid devices.
  68. raidctl -P all

  69. swapctl -A -t blk

  70. 是否为快速启动,  如果是,跳过磁盘检测, 如果是自动启动,
  71. 则使用fscp进行磁盘检测, 如果在检测中出现什么错误,
  72. 会打印出case中的设置的错误信息:
  73. if [ -e /fastboot ]; then
  74.         echo "Fast boot: skipping disk checks."
  75. elif [ $1x = autobootx ]; then
  76.         echo "Automatic boot in progress: starting file system checks."
  77.         fsck -p
  78.         case $? in
  79.         0)
  80.                 ;;
  81.         2)
  82.                 exit 1
  83.                 ;;
  84.         4)
  85.                 echo "Rebooting..."
  86.                 reboot
  87.                 echo "Reboot failed; help!"
  88.                 exit 1
  89.                 ;;
  90.         8)
  91.                 echo "Automatic file system check failed; help!"
  92.                 exit 1
  93.                 ;;
  94.         12)
  95.                 echo "Boot interrupted."
  96.                 exit 1
  97.                 ;;
  98.         130)
  99.                 # interrupt before catcher installed
  100.                 exit 1
  101.                 ;;
  102.         *)
  103.                 echo "Unknown error; help!"
  104.                 exit 1
  105.                 ;;
  106.         esac
  107. fi

  108. trap "echo 'Boot interrupted.'; exit 1" 3

  109. mount根文件系统
  110. umount -a >/dev/null 2>&1
  111. mount -a -t nonfs
  112. mount -uw /                # root on nfs requires this, others aren't hurt
  113. rm -f /fastboot                # XXX (root now writeable)

  114. 读取/etc/rc.conf配置文件
  115. # pick up option configuration
  116. . /etc/rc.conf

  117. # set flags on ttys.  (do early, in case they use tty for SLIP in netstart)
  118. echo 'setting tty flags'
  119. ttyflags -a

  120. 查看/etc/rc.conf中是否将pf设置为启动, 如果是, 执行if中的语句块:
  121. if [ "X${pf}" != X"NO" ]; then
  122.         RULES="block all"
  123.         RULES="$RULES\npass on lo0"
  124.         RULES="$RULES\npass in proto tcp from any to any port 22 keep state"
  125.         RULES="$RULES\npass out proto { tcp, udp } from any to any port 53 keep state"
  126.         RULES="$RULES\npass out inet proto icmp all icmp-type echoreq keep state"
  127.         RULES="$RULES\npass proto { pfsync, carp }"
  128.         case `sysctl vfs.mounts.nfs 2>/dev/null` in
  129.         *[1-9]*)
  130.                 # don't kill NFS
  131.                 RULES="scrub in all no-df\n$RULES"
  132.                 RULES="$RULES\npass in proto udp from any port { 111, 2049 } to any"
  133.                 RULES="$RULES\npass out proto udp from any to any port { 111, 2049 }"
  134.                 ;;
  135.         esac
  136.         echo $RULES | pfctl -f - -e
  137. fi

  138. 如果有/etc/sysctl.conf文件, 则读取文件, 进行设置:
  139. if [ -f /etc/sysctl.conf ]; then
  140. (
  141.         # delete comments and blank lines
  142.         set -- `stripcom /etc/sysctl.conf`
  143.         while [ $# -ge 1 ] ; do
  144.                 sysctl $1
  145.                 shift
  146.         done
  147. )
  148. fi

  149. 读取/etc/netstat文件
  150. # set hostname, turn on network
  151. echo 'starting network'
  152. . /etc/netstart

  153. 如果设置pf为启动, 现在检测pf_rules文件是否存在,
  154. 如存在, 载入规则文件:
  155. if [ "X${pf}" != X"NO" ]; then
  156.         if [ -f ${pf_rules} ]; then
  157.                 pfctl -f ${pf_rules}
  158.         fi
  159. fi


  160. mount /usr分区, /var分区:
  161. mount /usr >/dev/null 2>&1
  162. mount /var >/dev/null 2>&1

  163. 设置系统随机random:
  164. # if there's no /var/db/host.random, make one through /dev/urandom
  165. if [ ! -f /var/db/host.random ]; then
  166.         dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 \
  167.                 >/dev/null 2>&1
  168.         chmod 600 /var/db/host.random >/dev/null 2>&1
  169. else
  170.         dd if=/var/db/host.random of=/dev/urandom bs=1024 count=64 \
  171.             > /dev/null 2>&1
  172.         dd if=/var/db/host.random of=/dev/arandom bs=1024 count=64 \
  173.             > /dev/null 2>&1
  174. fi

  175. # reset seed file, so that if a shutdown-less reboot occurs,
  176. # the next seed is not a repeat
  177. dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 \
  178.     > /dev/null 2>&1

  179. # clean up left-over files
  180. rm -f /etc/nologin
  181. rm -f /var/spool/lock/LCK.*
  182. rm -f /var/spool/uucp/STST/*
  183. (cd /var/run && { test -r dhclient.pid && dhclient_pid=`cat
  184. dhclient.pid`; rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; test -n "$dhclient_pid" && echo "$dhclient_pid" > dhclient.pid; })
  185. (cd /var/authpf && rm -rf -- *)


  186. 将启动信息写入/var/run/dmesg.boot:
  187. # save a copy of the boot messages
  188. dmesg >/var/run/dmesg.boot


  189. echo 'starting system logger'
  190. rm -f /dev/log

  191. 测试是否启动named 服务器, 是则删除/var/named/dev/log下的日志文件,
  192. 使用syslogd_flags来进行日志记录:
  193. if [ "X${named_flags}" != X"NO" ]; then
  194.         rm -f /var/named/dev/log
  195.         syslogd_flags="${syslogd_flags} -a /var/named/dev/log"
  196. fi
  197. if [ -d /var/empty ]; then
  198.         rm -f /var/empty/dev/log
  199.         mkdir -p -m 0555 /var/empty/dev
  200.         syslogd_flags="${syslogd_flags} -a /var/empty/dev/log"
  201. fi
  202. syslogd ${syslogd_flags}

  203. pf的日志记录:
  204. if [ X"${pf}" != X"NO" -a X"${pflogd_flags}" != X"NO" ]; then
  205.         ifconfig pflog0 up
  206.         pflogd ${pflogd_flags}
  207. fi

  208. 如果启动了named,则启动if语句块中的内容:
  209. # $named_flags is imported from /etc/rc.conf;
  210. # if $named_flags != NO, named is run.
  211. if [ "X${named_flags}" != X"NO" ]; then
  212.         if ! cmp -s /etc/rndc.key /var/named/etc/rndc.key ; then
  213.                 echo -n "rndc-confgen: generating new shared secret... "
  214.                 if /usr/sbin/rndc-confgen -a -t /var/named >/dev/null 2>&1; then
  215.                         chmod 0640 /var/named/etc/rndc.key >/dev/null 2>&1
  216.                         echo done.
  217.                 else
  218.                         echo failed.
  219.                 fi
  220.         fi

  221.         echo 'starting named';                named $named_flags
  222. fi

  223. # $isakmpd_flags is imported from /etc/rc.conf;
  224. # If $isakmpd_flags == NO or /etc/isakmpd/isakmpd.policy doesn't exist, then
  225. # isakmpd isn't run.
  226. if [ "X${isakmpd_flags}" != X"NO" -a -e /etc/isakmpd/isakmpd.policy ]; then
  227.         echo 'starting isakmpd';        isakmpd ${isakmpd_flags}
  228. fi

  229. echo -n 'starting rpc daemons:'

  230. 这个是为RPC服务启动的:
  231. # $portmap is imported from /etc/rc.conf;
  232. # if $portmap == YES, the portmapper is started.
  233. if [ X"${portmap}" = X"YES" ]; then
  234.         echo -n ' portmap';                portmap
  235. fi

  236. if [ -d /var/yp/binding -a X`domainname` != X ]; then
  237.         if [ -d /var/yp/`domainname` ]; then
  238.                 # yp server capabilities needed...
  239.                 echo -n ' ypserv';                ypserv ${ypserv_flags}
  240.                 #echo -n ' ypxfrd';                ypxfrd
  241.         fi

  242.         echo -n ' ypbind';                ypbind

  243.         if [ X"${yppasswdd_flags}" != X"NO" -a -d /var/yp/`domainname` ]; then
  244.                 # if we are the master server, run rpc.yppasswdd
  245.                 _host1=`ypwhich -m passwd 2> /dev/null`
  246.                 _host2=`hostname`
  247.                 if [ `grep '^lookup' /etc/resolv.conf | grep yp | wc -c` -ne 0 ]; then
  248.                         _host1=`ypmatch $_host1 hosts | cut -d'        ' -f2`
  249.                         _host2=`ypmatch $_host2 hosts | cut -d'        ' -f2 | head -1`
  250.                 else
  251.                         _host1=`nslookup $_host1 | grep '^Name: ' | \
  252.                             sed -e 's/^Name:    //'`
  253.                         _host2=`nslookup $_host2 | grep '^Name: ' | \
  254.                             sed -e 's/^Name:    //'`
  255.                 fi
  256.                 if [ "$_host2" = "$_host1" ]; then
  257.                         echo -n ' rpc.yppasswdd'
  258.                         rpc.yppasswdd ${yppasswdd_flags}
  259.                 fi
  260.         fi
  261. fi

  262. NFS服务器启动脚本处:
  263. # $nfs_server is imported from /etc/rc.conf;
  264. # if $nfs_server == YES, the machine is setup for being an nfs server
  265. if [ X${nfs_server} = X"YES" -a -s /etc/exports -a \
  266.     `sed -e '/^#/d' < /etc/exports | wc -l` -ne 0 ]; then
  267.         rm -f /var/db/mountdtab
  268.         echo -n > /var/db/mountdtab
  269.         echo -n ' mountd';                mountd
  270.         echo -n ' nfsd';                nfsd ${nfsd_flags}
  271.         if [ X${lockd} = X"YES" ]; then
  272.                 echo -n ' rpc.lockd';        rpc.lockd
  273.         fi
  274. fi

  275. amd启动脚本:
  276. if [ X${amd} = X"YES" -a -e ${amd_master} ]; then
  277.         echo -n ' amd'
  278.         (cd /etc/amd; amd -l syslog -x error,noinfo,nostats -p \
  279.             -a ${amd_dir} `cat ${amd_master}` > /var/run/amd.pid )
  280. fi

  281. rdate启动脚本:
  282. # run rdate before timed
  283. if [ X"${rdate_flags}" != X"NO" ]; then
  284.         echo -n ' rdate';        rdate -s ${rdate_flags}
  285. fi

  286. timed时间服务器启动脚本:
  287. # $timed_flags is imported from /etc/rc.conf;
  288. # if $timed_flags == NO, timed isn't run.
  289. if [ "X${timed_flags}" != X"NO" ]; then
  290.         echo -n ' timed'; timed $timed_flags
  291. fi
  292. echo '.'

  293. mount -a -t nfs

  294. swapctl -A -t noblk

  295. # /var/crash should be a directory or a symbolic link
  296. # to the crash directory if core dumps are to be saved.
  297. if [ -d /var/crash ]; then
  298.         savecore ${savecore_flags} /var/crash
  299. fi

  300. if [ "X${afs}" = X"YES" -a -c /dev/xfs0 ]; then
  301.         echo -n 'mounting afs:'
  302.         mkdir -p -m 0755 /afs
  303.         mount -t xfs /dev/xfs0 /afs
  304.         /usr/libexec/afsd ${afsd_flags}
  305.         echo ' done.'
  306. fi

  307. 磁盘限额的启动脚本:
  308. if [ "X${check_quotas}" = X"YES" ]; then
  309.         echo -n 'checking quotas:'
  310.         quotacheck -a
  311.         echo ' done.'
  312.         quotaon -a
  313. fi

  314. # build ps databases
  315. echo -n 'building ps databases:'
  316. echo -n " kvm"
  317. kvm_mkdb
  318. echo -n " dev"
  319. dev_mkdb
  320. echo "."

  321. chmod 666 /dev/tty[pqrstuvwxyzPQRST]*
  322. chown root:wheel /dev/tty[pqrstuvwxyzPQRST]*

  323. # check the password temp/lock file
  324. if [ -f /etc/ptmp ]; then
  325.         logger -s -p auth.err \
  326.         'password file may be incorrect -- /etc/ptmp exists'
  327. fi

  328. echo clearing /tmp

  329. # prune quickly with one rm, then use find to clean up /tmp/[lq]*
  330. # (not needed with mfs /tmp, but doesn't hurt there...)
  331. (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
  332.     find . ! -name . ! -name lost+found ! -name quota.user \
  333.         ! -name quota.group -execdir rm -rf -- {} \; -type d -prune)

  334. 如果系统上安装了XFREE, 存在/usr/X11R6/lib文件, 则执行下面的脚本:
  335. # create Unix sockets directories  for X if needed and make sure they have
  336. # correct permissions
  337. if [ -d /usr/X11R6/lib ]; then
  338.         for d in /tmp/.X11-unix /tmp/.ICE-unix ; do
  339.                 if [ -d $d ]; then
  340.                         if [ `ls -ld $d | cut -d' ' -f4` != root ]; then
  341.                                 chown root $d
  342.                         fi
  343.                         if [ `ls -ld $d | cut -d' ' -f1` != drwxrwxrwt ]; then
  344.                                 chmod 1777 $d
  345.                         fi
  346.                 elif [ -e $d ]; then
  347.                         echo "Error: $d exists and isn't a directory."
  348.                 else
  349.                         mkdir -m 1777 $d
  350.                 fi
  351.         done
  352. fi

  353. 设置系统安装级别:
  354. [ -f /etc/rc.securelevel ] && . /etc/rc.securelevel
  355. if [ X${securelevel} != X"" ]; then
  356.         echo -n 'setting kernel security level: '
  357.         sysctl kern.securelevel=${securelevel}
  358. fi

  359. 每次登陆系统时的信息, 同freebsd的motd一样,
  360. 只不过在freebsd可以在rc.conf中关闭它,
  361. 而在openbsd则需要修改此处才能关闭它:
  362. # patch /etc/motd
  363. if [ ! -f /etc/motd ]; then
  364.         install -c -o root -g wheel -m 664 /dev/null /etc/motd
  365. fi
  366. T=`mktemp /tmp/_motd.XXXXXXXXXX`
  367. if [ $? -eq 0 ]; then
  368.         sysctl -n kern.version | sed 1q > $T
  369.         echo "" >> $T
  370.         sed '1,/^$/d' < /etc/motd >> $T
  371.         cmp -s $T /etc/motd || cp $T /etc/motd
  372.         rm -f $T
  373. fi

  374. if [ -f /var/account/acct ]; then
  375.         echo 'turning on accounting';        accton /var/account/acct
  376. fi

  377. if [ -f /sbin/ldconfig ]; then
  378.         echo 'creating runtime link editor directory cache.'
  379.         if [ -d /usr/local/lib ]; then
  380.                 shlib_dirs="/usr/local/lib $shlib_dirs"
  381.         fi
  382.         if [ -d /usr/X11R6/lib ]; then
  383.                 shlib_dirs="/usr/X11R6/lib $shlib_dirs"
  384.         fi
  385.         ldconfig $shlib_dirs
  386. fi

  387. 如果/usr/libexec/vi.recover是可执行文件则执行if语句块中的内容:
  388. if [ -x /usr/libexec/vi.recover ]; then
  389.         echo 'preserving editor files';        /usr/libexec/vi.recover
  390. fi

  391. 创建ssh的主机密匙, 通常在系统第一次启动时创建,
  392. 当然如果你删除了/etc/ssh/下的文件, 它也会再重新创建一个新的:
  393. if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
  394.         echo -n "ssh-keygen: generating new DSA host key... "
  395.         if /usr/bin/ssh-keygen -q -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''; then
  396.                 echo done.
  397.         else
  398.                 echo failed.
  399.         fi
  400. fi
  401. if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
  402.         echo -n "ssh-keygen: generating new RSA host key... "
  403.         if /usr/bin/ssh-keygen -q -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''; then
  404.                 echo done.
  405.         else
  406.                 echo failed.
  407.         fi
  408. fi
  409. if [ ! -f /etc/ssh/ssh_host_key ]; then
  410.         echo -n "ssh-keygen: generating new RSA1 host key... "
  411.         if /usr/bin/ssh-keygen -q -t rsa1 -f /etc/ssh/ssh_host_key -N ''; then
  412.                 echo done.
  413.         else
  414.                 echo failed.
  415.         fi
  416. fi

  417. echo -n starting network daemons:

  418. routed启动脚本:
  419. # $routed_flags are imported from /etc/rc.conf.
  420. # If $routed_flags == NO, routed isn't run.
  421. if [ "X${routed_flags}" != X"NO" ]; then
  422.         echo -n ' routed';                routed $routed_flags
  423. fi

  424. # $mrouted_flags is imported from /etc/rc.conf;
  425. # If $mrouted_flags == NO, then mrouted isn't run.
  426. if [ "X${mrouted_flags}" != X"NO" ]; then
  427.         echo -n ' mrouted';                mrouted $mrouted_flags
  428. fi

  429. bgpd启动脚本:
  430. if [ "X${bgpd_flags}" != X"NO" ]; then
  431.         echo -n ' bgpd';                /usr/sbin/bgpd $bgpd_flags
  432. fi

  433. dhcpd服务器启动脚本:
  434. # $dhcpd_flags is imported from /etc/rc.conf
  435. # If $dhcpd_flags == NO or /etc/dhcpd.conf doesn't exist, then dhcpd isn't run.
  436. if [ "X${dhcpd_flags}" != X"NO" -a -f /etc/dhcpd.conf ]; then
  437.         touch /var/db/dhcpd.leases
  438.         if [ -f /etc/dhcpd.interfaces ]; then
  439.                 dhcpd_ifs=`stripcom /etc/dhcpd.interfaces`
  440.         fi
  441.         echo -n ' dhcpd';        /usr/sbin/dhcpd ${dhcpd_flags} ${dhcpd_ifs}
  442. fi

  443. ifconfig设置网络:
  444. if ifconfig lo0 inet6 >/dev/null 2>&1; then
  445.         fw=`sysctl -n net.inet6.ip6.forwarding`
  446.         if [ "X${fw}" == X"0" ]; then
  447.                 # $rtsold_flags is imported from /etc/rc.conf;
  448.                 # If $rtsold_flags == NO, then rtsold isn't run.
  449.                 if [ "X${rtsold_flags}" != X"NO" ]; then
  450.                         echo -n ' rtsold'
  451.                         /usr/sbin/rtsold ${rtsold_flags}
  452.                 fi
  453.         else
  454.                 # $route6d_flags is imported from /etc/rc.conf;
  455.                 # If $route6d_flags == NO, then route6d isn't run.
  456.                 if [ "X${route6d_flags}" != X"NO" ]; then
  457.                         echo -n ' route6d'
  458.                         /usr/sbin/route6d ${route6d_flags}
  459.                 fi
  460.                 # $rtadvd_flags is imported from /etc/rc.conf;
  461.                 # If $rtadvd_flags == NO, then rtadvd isn't run.
  462.                 if [ "X${rtadvd_flags}" != X"NO" ]; then
  463.                         echo -n ' rtadvd'
  464.                         /usr/sbin/rtadvd ${rtadvd_flags}
  465.                 fi
  466.         fi
  467. fi

  468. rwhod服务器启动脚本:
  469. # $rwhod is imported from /etc/rc.conf;
  470. # if $rwhod == YES, rwhod is run.
  471. if [ X${rwhod} = X"YES" ]; then
  472.         echo -n ' rwhod';                rwhod
  473. fi

  474. 打印服务器启动脚本:
  475. if [ "X${lpd_flags}" != X"NO" ]; then
  476.         echo -n ' printer';                lpd ${lpd_flags}
  477. fi

  478. 邮件服务器sendmail启动脚本:
  479. # $sendmail_flags is imported from /etc/rc.conf;
  480. # If $sendmail_flags == NO or /etc/mailer.conf doesn't exist, then
  481. # sendmail isn't run.  We call sendmail with a full path so that
  482. # SIGHUP works.  Note that /usr/sbin/sendmail may actually call a
  483. # mailer other than sendmail, depending on /etc/mailer.conf.
  484. if [ "X${sendmail_flags}" != X"NO" -a -s /etc/mailer.conf ]; then
  485.         echo -n ' sendmail';                ( /usr/sbin/sendmail ${sendmail_flags} >/dev/null 2>&1 & )
  486. fi

  487. web服务器启动脚本:
  488. if [ "X${httpd_flags}" != X"NO"  ]; then
  489.         # Clean up left-over httpd locks
  490.         rm -f /var/www/logs/{ssl_mutex,httpd.lock,accept.lock}.*
  491.         echo -n ' httpd';                /usr/sbin/httpd ${httpd_flags}
  492. fi

  493. FTP服务器启动脚本:
  494. if [ "X${ftpd_flags}" != X"NO" ]; then
  495.         echo -n ' ftpd';                /usr/libexec/ftpd ${ftpd_flags}
  496. fi

  497. if [ "X${identd_flags}" != X"NO" ]; then
  498.         echo -n ' identd';                /usr/libexec/identd ${identd_flags}
  499. fi

  500. INETD服务器启动脚本:
  501. if [ X${inetd} = X"YES" -a -e /etc/inetd.conf ]; then
  502.         echo -n ' inetd';                inetd
  503. fi

  504. SSH服务器启动脚本:
  505. if [ X"${sshd_flags}" != X"NO" ]; then
  506.         echo -n ' sshd';                /usr/sbin/sshd ${sshd_flags};
  507. fi

  508. if [ "X${spamd_flags}" != X"NO" ]; then
  509.         if [ "X${spamd_grey}" != X"NO" ]; then
  510.                 spamd_flags="${spamd_flags} -g"
  511.         fi
  512.         echo -n ' spamd';                /usr/libexec/spamd ${spamd_flags}
  513.         /usr/libexec/spamd-setup
  514.         if [ "X${spamd_grey}" != X"NO" ]; then
  515.                 echo -n ' spamlogd'
  516.                 /usr/libexec/spamlogd
  517.         fi
  518. fi

  519. # $rarpd_flags is imported from /etc/rc.conf;
  520. # If $rarpd_flags == NO or /etc/ethers doesn't exist, then
  521. # rarpd isn't run.
  522. if [ "X${rarpd_flags}" != X"NO" -a -s /etc/ethers ]; then
  523.         echo -n ' rarpd';                rarpd ${rarpd_flags}
  524. fi

  525. # $bootparamd_flags is imported from /etc/rc.conf;
  526. # If $bootparamd_flags == NO or /etc/bootparams doesn't exist, then
  527. # bootparamd isn't run.
  528. if [ "X${bootparamd_flags}" != X"NO" -a -s /etc/bootparams ]; then
  529.         echo -n ' rpc.bootparamd';        rpc.bootparamd ${bootparamd_flags}
  530. fi

  531. # $rbootd_flags is imported from /etc/rc.conf;
  532. # If $rbootd_flags == NO or /etc/rbootd.conf doesn't exist, then
  533. # rbootd isn't run.
  534. if [ "X${rbootd_flags}" != X"NO" -a -s /etc/rbootd.conf ]; then
  535.         echo -n ' rbootd';                rbootd ${rbootd_flags}
  536. fi

  537. # $mopd_flags is imported from /etc/rc.conf;
  538. # If $mopd_flags == NO or /tftpboot/mop doesn't exist, then
  539. # mopd isn't run.
  540. if [ "X${mopd_flags}" != X"NO" -a -d /tftpboot/mop ]; then
  541.         echo -n ' mopd';                mopd ${mopd_flags}
  542. fi

  543. echo '.'


  544. if [ -x /sbin/wsconsctl -a -f /etc/wsconsctl.conf ]; then
  545. (
  546.         # delete comments and blank lines
  547.         save_IFS="$IFS"
  548.         IFS="
  549. "
  550.         set -- `stripcom /etc/wsconsctl.conf`
  551.         IFS="$save_IFS"
  552.         while [ $# -ge 1 ] ; do
  553.                 eval /sbin/wsconsctl -w $1
  554.                 shift
  555.         done
  556. )
  557. fi

  558. 键盘设置:
  559. if [ -f /sbin/kbd -a -f /etc/kbdtype ]; then
  560.         kbd `cat /etc/kbdtype`
  561. fi

  562. kerberosV设置:
  563. # KerberosV master KDC
  564. if [ X${krb5_master_kdc} = X"YES" ]; then
  565.         echo 'KerberosV master KDC'
  566.         /usr/libexec/kdc &
  567.         /usr/libexec/kadmind &
  568.         /usr/libexec/kpasswdd &
  569. fi

  570. # KerberosV slave KDC
  571. if [ X${krb5_slave_kdc} = X"YES" ]; then
  572.         echo 'KerberosV slave KDC'
  573.         /usr/libexec/kdc &
  574.         # Remember to enable hpropd in inetd.conf
  575. fi

  576. [ -f /etc/rc.local ] && . /etc/rc.local

  577. echo -n standard daemons:

  578. apmd启动脚本:
  579. # $apmd_flags is imported from /etc/rc.conf;
  580. # don't run daemon if $apmd_flags == NO or /usr/sbin/apmd doesn't exist
  581. if [ "X${apmd_flags}" != X"NO" -a -x /usr/sbin/apmd ]; then
  582.         echo -n ' apmd';        /usr/sbin/apmd ${apmd_flags}
  583. fi

  584. if [ X"${sensorsd_flags}" != X"NO" ]; then
  585.         echo -n ' sensorsd';        /usr/sbin/sensorsd ${sensorsd_flags}
  586. fi

  587. echo -n ' cron';                cron

  588. echo '.'

  589. date

  590. mouse控制:
  591. if [ "X${wsmoused_flags}" != X"NO" -a -x /usr/sbin/wsmoused ]; then
  592.         echo 'starting wsmoused...';        /usr/sbin/wsmoused ${wsmoused_flags}
  593. fi

  594. 如果装了x, 则这个xdm要设置为启动, X才能用:
  595. # Alternatively, on some architectures, xdm may be started in /etc/ttys.
  596. if [ "X${xdm_flags}" != X"NO" ]; then
  597.         echo 'starting xdm...';                /usr/X11R6/bin/xdm ${xdm_flags}
  598. fi

  599. exit 0
复制代码

好了, 马马虎虎的说一些, 今天上午体检了一下,
然后下午就乱写了这一篇, 跟大伙一起读读/etc/rc文件,
了解了解系统启动时的各类信息和系统设置。
各位对这些有不明白的地方可指出来, 我将它加进文章去!

欢迎参加openbsd项目, 欢迎访问项目主页:http://openbsd.linuxsir.cn
发表于 2004-6-4 12:09:06 | 显示全部楼层

好文,多谢

好文,多谢
发表于 2004-6-4 19:52:47 | 显示全部楼层
楼主开始学shell了 ??
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表