前言
linux有自己一套完整的启动 体系,抓住了linux启动 的脉络,linux的启动 过程将不再神秘。
阅读之前建议先看一下附图。
本文中假设inittab中设置的init tree为:
/etc/rc.d/rc0.d
/etc/rc.d/rc1.d
/etc/rc.d/rc2.d
/etc/rc.d/rc3.d
/etc/rc.d/rc4.d
/etc/rc.d/rc5.d
/etc/rc.d/rc6.d
/etc/rc.d/init.d
目录 
1. 关于linux的启动 
2. 关于rc.d
3. 启动 脚本 示例
4. 关于rc.local
5. 关于bash启动 脚本 
6. 关于开机程序的自动启动 
1. 关于linux的启动 
init是所有进程之父 
init读取/etc/inittab,执行rc.sysinit脚本 
(注意文件名是不一定的,有些unix甚至会将语句直接写在inittab中)
rc.sysinit脚本 作了很多工作:

init $PATH

config network

start swap function

set hostname

check root file system, repair if needed

check root space

....

rc.sysinit根据inittab执行rc?.d脚本 
linux是多用户系统,getty是多用户与单用户的分水岭
在getty之前运行的是系统脚本 
2. 关于rc.d 
所有启动 脚本 放置在
/etc/rc.d/init.d下 
rc?.d中放置的是init.d中脚本 的链接,命名格式是:
S{number}{name}
K{number}{name}
S开始的文件向脚本 传递start参数
K开始的文件向脚本 传递stop参数
number决定执行的顺序
3. 启动 脚本 示例 
这是一个用来启动 httpd的
/etc/rc.d/init.d/apache 脚本 :

CODE:


#!/bin/bash

source /etc/sysconfig/rc

source $rc_functions

case "$1" in

start)

echo "Starting Apache daemon..."

/usr/local/apache2/bin/apachectl -k start

evaluate_retval

;;

stop)

echo "Stopping Apache daemon..."

/usr/local/apache2/bin/apachectl -k stop

evaluate_retval

;;

restart)

echo "Restarting Apache daemon..."

/usr/local/apache2/bin/apachectl -k restart

evaluate_retval

;;

status)

statusproc /usr/local/apache2/bin/httpd

;;

*)

echo "Usage: $0 {start|stop|restart|status}"

exit 1

;;

esac

可以看出他接受start,stop,restart,status参数

然后可以这样建立rc?.d的链接:

CODE:


cd /etc/rc.d/init.d &&

ln -sf ../init.d/apache ../rc0.d/K28apache &&

ln -sf ../init.d/apache ../rc1.d/K28apache &&

ln -sf ../init.d/apache ../rc2.d/K28apache &&

ln -sf ../init.d/apache ../rc3.d/S32apache &&

ln -sf ../init.d/apache ../rc4.d/S32apache &&

ln -sf ../init.d/apache ../rc5.d/S32apache &&

ln -sf ../init.d/apache ../rc6.d/K28apache

4. 关于rc.local
经常使用的 rc.local 则完全是习惯问题,不是标准。
各个发行版有不同的实现方法,可以这样实现:

CODE:


touch /etc/rc.d/rc.local

chmod +x /etc/rc.d/rc.local

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc1.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc2.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc3.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc4.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc5.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc6.d/S999rc.local

5. 关于bash启动 脚本 
/etc/profile 
/etc/bashrc
~/.bash_profile
~/.bashrc
是bash的启动 脚本 
一般用来设置单用户的启动 环境,也可以实现开机单用户的程序,但要明确他们都是属于bash范畴而不是系统范畴。
他们的具体作用介绍如下:
/bin/bash这个命令解释程序(后面简称shell)使用了一系列启动 文件来建立一个运行环境:

/etc/profile 

/etc/bashrc

~/.bash_profile

~/.bashrc

~/.bash_logout 
每一个文件都有特殊的功用并对登陆和交互环境有不同的影响。
/etc/profile 和
~/.bash_profile 是在启动 一个交互登陆shell的时候 被调用。
/etc/bashrc 和 ~/.bashrc 是在一个交互的非登陆shell启动 的时候 被调用。
~/.bash_logout 在用户注销登陆的时候 被读取
一 个交互的登陆shell会在 /bin/login 成功登陆之后运行。一个交互的非登陆shell是通过命令行来运行的,如[prompt]$/bin/bash。一般一个非交互的shell出现在运行 shell脚本 的时候 。之所以叫非交互的shell,是因为它不在命令行上等待输入而只是执行脚本 程序。
6. 关于开机程序的自动启动 
系统脚本 可以放置在/etc/rc.d/init.d中并建立/etc/rc.d/rc?.d链接,也可以直接放置在/etc/rc.d/rc.local中。
init.d脚本 包含完整的start,stop,status,reload等参数,是标准做法,推荐使用。 
为特定用户使用的程序(如有的用户需要使用中文输入法而有的不需要)放置在~/中的bash启动 脚本 中。

【Linux开发】Linux启动脚本设置的更多相关文章

  1. 开发rsync启动脚本2

    使用函数更加规范的开发rsync启动脚本 #!/bin/bash #chkconfig: #description: create by vincen . /etc/init.d/functions ...

  2. 嵌入式linux开发uboot启动内核的机制(二)

    一.嵌入式系统的分区 嵌入式系统部署在Flash设备上时,对于不同SoC和Flash设备,bootloader.kernel.rootfs的分区是不同的.三星S5PV210规定启动设备的分区方案如下: ...

  3. linux中tomcat启动脚本:关闭、发布、重启、测试是否成功

    说明 在使用jenkins持续集成时,需要实现自动发布包到tomcat.该脚本实现了在jenkins将包发送到linux服务器上后的自动关闭.发布.启动.测试启动是否成功的过程 思路 该思路以tomc ...

  4. linux 的开机启动脚本顺序

    linux 开机启动脚本顺序 linux 开机启动脚本顺序. 第一步:启动内核 第二步:执行init (配置文件/etc/inittab) 第三步:启动相应的脚本,并且打开终端/etc/init.d  ...

  5. linux系统初始化——启动脚本是如何工作的

    启动脚本是如何工作的 Linux 使用的是基于 运行级(run-levels) 概念的称为 SysVinit 的专用启动工具.它在不同的系统上可能是完全不一样的,所以不能认为一个脚本在某个 Linux ...

  6. 开发nginx启动脚本及开机自启管理(case)

    往往我们在工作中需要自行写一些脚本来管理服务,一旦服务异常或宕机等问题,脚本无法自行管理,当然我们可以写定时任务或将需要管理的脚本加入自启等方法来避免这种尴尬的事情,case适用与写启动脚本,下面给大 ...

  7. 嵌入式linux开发uboot启动过程源码分析(一)

    一.uboot启动流程简介 与大多数BootLoader一样,uboot的启动过程分为BL1和BL2两个阶段.BL1阶段通常是开发板的配置等设备初始化代码,需要依赖依赖于SoC体系结构,通常用汇编语言 ...

  8. linux下服务启动脚本

    #!/usr/bin/env python# -*- coding: utf-8 -*-# @File : deployment.py# @Author: Anthony.waa# @Date : 2 ...

  9. Linux创建Jenkins启动脚本以及开机启动服务

    1.jenkins.sh #!/bin/bash ###主要目的用于开机启动服务,不然 启动jenkins.war包没有java -jar的权限 JAVA_HOME=/usr/lib/jdk1.8.0 ...

随机推荐

  1. sed编辑

    data4.txt this is a test of the test scriptthis is the second test of the trial script data6.txt thi ...

  2. echarts实现心脏图的滚动三种实现方法

    1.改变dataset 2.移动scrollbar 3.修改echarts自带的dataZoom的start和end

  3. Linux 性能测试工具Lmbench详解

    Linux 性能测试工具Lmbench详解 2010-06-04 16:07 佚名 评测中心 字号:T | T Lmbench 是一套简易可移植的,符合ANSI/C 标准为UNIX/POSIX 而制定 ...

  4. kong CentOS7网关安装

    1.先安装postgres数据库,yum安装.yum install postgresql96yum install postgresql96-server配置环境变量export PGDATA=/v ...

  5. 各种注意事项(还有c++的一些操作)

    转c++时间: 2017年8月9号 1.记得打头文件 2.=与==的区别(赋值|比较) 3.各种运算符的比较级(与Pascal不同),主要是==与位运算 *4.在OJ上scanf和printf时间优于 ...

  6. 9. ClustrixDB主从复制

    一.在线添加从库 主集群: 10.1.1.23:5306 从集群: 10.1.3.88:5306 主库开启binlog MySQL [(none)]> CREATE BINLOG 'clustr ...

  7. CentOS7安装codeblocks

    1.yum -y install epel-release 2.yum clean all && yum makecache 3.yum -y install gtk2-devel c ...

  8. 配置文件:android:inputType参数类型说明

    输入字符 android:inputType="none"  --输入普通字符  android:inputType="text" --输入普通字符  andr ...

  9. NOIP2016考前做题(口胡)记录

    NOIP以前可能会持续更新 写在前面 NOIP好像马上就要到了,感觉在校内训练里面经常被虐有一种要滚粗的感觉(雾.不管是普及组还是提高组,我都参加了好几年了,结果一个省一都没有,今年如果还没有的话感觉 ...

  10. VGA/DVI/HDMI/DP/Type-C等常用显示接口对比介绍

    在我们的生活中,无论是电脑.电视还是投影设备等等,都离不开视频输出接口,尤其在显卡上面,通常会出现3种甚至更多的接口.很多人并不了解其中的区别,觉得只要有画面输出就可以了,其实对于很多显示器来说并非如 ...