suse 服务启动顺序

来源:互联网 发布:小学生ppt软件下载 编辑:程序博客网 时间:2024/05/16 05:06

This item inspiredby Ken. And in order to keep this answer relatively short, I have toskip a bunch of pre-reqs. I’m going to assume that you understandservice startup and run-levels in Linux, and maybe have triedspecifying start-order in RedHat… This is where my thinking went whenanswering the question for Ken, so that’s what you get here. Anyway,back to the question at hand…

You don’t. ;) Just kidding… *kinda*…

So you already know how to cause services to start and stop at various runlevels using the chkconfig tool on RedHat (and the RedHat derivatives, which I just refer to as RedHat) and Suse, or the insserv tool on Suse. But *now* what you want to do is enforce the service load sequence by number.

“Ah-hah!”, you say, because you are an old-school Unix guy (yes, Your Linux Guy knows about you and your ways ;) ), and you know that all you have to do is hand-write a script, and throw it (or a symlink) into the appropriate rc[?].d directory, right? Wrong. Well, you *could* do that, but as soon as you run chkconfig on Suse, it will re-order your service based on some other criteria… more on that in a moment.

First some background on RedHat…

Many of you are used to the tool chkconfig. In order tospecify load order in RedHat, you make sure that one important linesimilar to the following exists in the start script in the /etc/rc.d/init.d directory:

# chkconfig: 35 98 01

…note that the leading pound/hash symbol indicates that it is a comment; this is important. Then, after the chkconfig:,the next items are as follows: runlevels in which to start (3 and 5),start sequence number (98, which is very late in the order), andstop/kill sequence number (01). Yours, of course, will vary. And — veryimportant here, folks — you need to run chkconfig afteryour modifications for it to take effect; it goes through and reads allthose comments and places things in the appropriate place.

Now, on to the Suse insserv method…

Suse uses a similar philosophy to RedHat’s chkconfig with insservonly insofar as there are a certain set of comments in the start scriptrequired to enforce start order. However, instead of you having theluxury of being able to specify *the exact number* for the startupscript, you only get to specify things that should be started *before*or *after* your script. This will effectively do the same thing withthe arrangement, though you might not get the pretty number S98 you were hoping for.

So, specifically, here is an example comment block with just a reasonable minimum, for a fake application called myapp:

### BEGIN INIT INFO
# Provides: myapp
# Required-Start: $ALL
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Description: My App is cool
# Short-Description: My App
### END INIT INFO

…this example will cause myapp to be one of the last things loaded (the $ALL is a special value, see below), in runlevel 3 or 5, and will stop at all other levels. On my machine, it puts myapp at S21, right before S21SuSEfirewall2_setup, which is numerically equal, but alphabetically later. And — just like with RedHat — you must run chkconfig or the Suse tool insserv for the scripts to be re-arranged and placed, ready to run. Its important to remember that on Suse, chkconfig is just a child to insserv,it is not the same exact tool as on RedHat. But like on RedHat, it willparse the comments fields and place the script in the appropriateplaces.

Now here’s how that actually works on Suse…
For Suse, the “Provides:” item in the script creates something called a“facility”. So in my example above, I’ve created a facility called “myapp“. Then, others scripts can reference that facility in specifying whether they should load before or after. For example, the sshd startup script provides a “sshd” facility (it does not have to be the same name as the daemon), so I could have put the following in my myapp script:

# Required-Start: $sshd

…and then myapp would have been placed to start right after sshd in the appropriate /etc/init.d/rc[?].d directory. On my machine, sshd is at S12… so if I did that, myapp would likely be at S13(the next higher number). Note that the facility is prefixed by adollar-sign when it referenced/called, but not when it is created inthe “Provides:” line. Also, the $ALL is aspecial all-inclusive facility value that means “all facilities”, andwhen used, it causes your script to be loaded after all others.

Warning: Some of the startup scripts in Suse have the RedHat chkconfigsyntax in them. Why? To mess with you. No, not really, but that’s whatit did to me when I was first figuring this stuff out. Especially sinceSuse has the chkconfig binary (which works on Suse to a lesser extent than on RedHat) for your convenience… and confusion…

Phew! Got it? Good.

Make sure to let me know if I missed something…

:)

原文出处:http://yourlinuxguy.com/?p=41

原创粉丝点击