Archive

Posts Tagged ‘SUSE’

Linux启动项机制

December 10th, 2008

通常我们都会希望一些服务在系统启动的时候能够自动运行,比如网站的服务,SVN服务等等。在Linux下面和这个功能有关的文件在/etc/rc.d(或者/etc, 不同的系统不一样)下。在这个目录下我们应该可以看到rc.0, rc.1, rc.2, rc.3, rc.4, rc.5, and rc.6, 他们分别对应于不同的运行模式,其中0和6保留为停机和重启。其余的模式在不同的机器上的定义不一定相同,我们可以查看/etc/inittab来找到自己系统上的默认模式和对于其他模式的说明. 在SuSe Linux下该文件的内容为:

# The default runlevel is defined here
id:5:initdefault:

# First script to be executed, if not booting in emergency (-b) mode
si::bootwait:/etc/init.d/boot

# /etc/init.d/rc takes care of runlevel handling
#
# runlevel 0  is  System halt   (Do not use this for initdefault!)
# runlevel 1  is  Single user mode
# runlevel 2  is  Local multiuser without remote network (e.g. NFS)
# runlevel 3  is  Full multiuser with network
# runlevel 4  is  Not used
# runlevel 5  is  Full multiuser with network and xdm
# runlevel 6  is  System reboot (Do not use this for initdefault!)
#
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
#l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6

…………

和其他大多数的Linux版本不同,SuSe没有提供一个rc.local的文件用来定制用户的启动程序,该脚本仅运行一次。在SuSe的论坛上我找到了两种方法可以替换rc.local.

首先要创建rc.local,然后向其中加入自己的运行脚本。可以通过yast2来将其添加到启动项,yast2是SuSe的一个基于GUI的启动控制程序。如果你在命令行下工作可以使用chkconfig命令: chokconfig -add [filename], 在我的SuSe上文件的名字不能是rc.local, 貌似中间的那个.不被接受,所以我改成了rclocal。

如果用命令行方式需要在rclocal的前面添加:

#!/bin/sh
### BEGIN INIT INFO
# Provides: rc.local
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: [your description]
### END INIT INFO

来配置该启动项的一些参数。这里的含义是rclocal会在3和5模式下被启动。

参考链接:

http://forums.opensuse.org/archives/sf-archives/archives-programming-scripting/317339-there-no-rc-local.html

http://www.linux.com/articles/114107

Author: gleery Categories: Linux Tags: , , ,