Chinaunix首页 | 论坛 | 博客
  • 博客访问: 57759
  • 博文数量: 27
  • 博客积分: 2040
  • 博客等级: 大尉
  • 技术积分: 265
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-03 17:21
文章分类
文章存档

2010年(14)

2009年(13)

我的朋友

分类: LINUX

2010-01-10 22:12:27


Allow me to give you a little introduction on the subject prior to the
proper howto. The Linux boot process can be split
up in three steps:


  • Loading the kernel
  • Device detection and configuration
  • Granting control to ‘init’


The ‘init’ program is a daemon that spawns all other processes in the
system. It is responsibe for loading the system
using initialization scripts, which are usually found at /etc/init.d.
There are two ways for init to operate, BSD and
SystemV. Typically, Linux systems use SystemV, though there are
distributions like Arch Linux or Slackware that use BSD.


The runlevel is a number used to identify the mode in which the
computer is. For example, a runlevel 0 would mean that
the computer is halted, while changing the runlevel to 6 would make
the computer reboot. There are 7 runlevels.
Runlevels from 1 to 5 usually differ in the programs that are
automatically started. Typically, runlevel 3 is used to
boot in text-only mode, while runlevel 5 will start the X server and
the desktop environment.


For each runlevel, there is a folder named rcN.d (where N stands for
the runlevel number) which contains symbolic links
to the some of the scripts located at /etc/init.d.


When changing the runlevel, what the system does is:


  • Changing directory to /etc/rcN.d or /etc/rc.d/rcN.d (depends on the
    distribution).
  • All the scripts that begin with K are executed in alphabetical order
    with the argument ‘stop’. Usually there are
    numbers after the K to be able to control the exact execution order.
  • All the scripts that begin with S are executed in alphabetical order
    with the argument ‘start’. As before, numbers are
    used to sort the scripts before execution.


If you want to learn more, you can find information about init and runlevels at:








Now lets get our hands dirty and learn how to make the BitNami stack
servers start at boot time :) Bear into mind that
you will need root privileges to do it.


- Debian-like distribution (Debian, Ubuntu, etc)


1. Copy the installdir/ctlscript.sh file to /etc/init.d . It is
advisable to rename this script to something more specific, like “bitnami-drupal”.


cp installdir/ctlscript.sh /etc/init.d/bitnami-drupal


2. We will use rc-update.d to add the script to the desired runlevels.

update-rc.d -f bitnami-drupal start 80 2 3 4 5 . stop 30 0 1 6 .



As you can see, we define the priority (80 for start and 30 for stop) and the runlevels in which the script will be executed. The result of this command will be something like


Adding system startup for /etc/init.d/bitnami-drupal … /etc/rc0.d/K30bitnami-bitnami-drupal → ../init.d/drupal /etc/rc1.d/K30bitnami-bitnami-drupal → ../init.d/drupal /etc/rc6.d/K30bitnami-drupal → ../init.d/bitnami-drupal /etc/rc2.d/S80bitnami-drupal → ../init.d/bitnami-drupal /etc/rc3.d/S80bitnami-drupal → ../init.d/bitnami-drupal /etc/rc4.d/S80bitnami-drupal → ../init.d/bitnami-drupal /etc/rc5.d/S80bitnami-drupal → ../init.d/bitnami-drupal



And that’s it, the servers will be loaded at boot time. To revert
the changes, just type


update-rc.d -f bitnami-drupal remove



- RedHat-like distribution (Red Hat, Fedora Core, CentOS, Suse, etc)


1. Copy the installdir/ctlscript.sh file to /etc/init.d . It is
advisable to rename this script to something more specific, like “bitnami-drupal”.


cp installdir/ctlscript.sh /etc/init.d/bitnami-drupal



2. You have to modify the script a little bit to make it work at
boot time. Just add the following lines at the beginning of the file


#!/bin/sh


#

  1. chkconfig: 2345 80 30

  2. description: BitNami Service


This means that the script will be executed in runlevels 2, 3, 4
and 5, with priority 80 to start, and 30 to stop.


3. Now, you only need chkconfig to install the script as a service.


chkconfig —add bitnami-drupal



And you’re done. To revert the changes, we will use chkconfig again


chkconfig —delete bitnami-drupal



That’s all! If you have comments or suggestions, please post at the
following topic on the forums


阅读(547) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~