linux 启动过程以及如何将进程加入开机自启
linux 启动流程

系统启动主要顺序就是:
1. 加载内核
2. 启动初始化进程
3. 确定运行级别
4. 加载开机启动程序
5. 用户登录
启动流程的具体细节可以看看Linux 的启动流程
第4步加载启动程序其实是两步:
- init进程逐一加载开机启动程序,其实就是运行指定目录里的启动脚本。
- 在运行完指定目录里面的程序后init进程还会去执行/etc/rc.local 这个脚本。
ps:“指定目录”是指在第3步中设置的运行级别对应的目录。
要完成我们的需求,我们使用第4步中的任意一种方式都可以。
方式一,chkconfig
以supervisord服务脚本为例:

#!/bin/sh
##
## /etc/rc.d/init.d/supervisord
##
#supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord # Source init functions
. /etc/rc.d/init.d/functions prog="supervisord"
prefix="/usr/"
exec_prefix="${prefix}"
PIDFILE="/var/run/supervisord.pid"
CONFIG="/etc/supervisord.conf"
prog_bin="${exec_prefix}bin/supervisord -c $CONFIG " function log_success_msg() {
echo "$@" "[ OK ]"
} function log_failure_msg() {
echo "$@" "[ OK ]"
} start()
{
#echo -n $"Starting $prog: "
#daemon $prog_bin --pidfile $PIDFILE
#[ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog failed"
#echo
if [ ! -r $CONFIG ]; then
log_failure_msg "config file doesn't exist (or you don't have permission to view)"
exit 4
fi if [ -e $PIDFILE ]; then
PID="$(pgrep -f $PIDFILE)"
if test -n "$PID" && kill -0 "$PID" &>/dev/null; then
# If the status is SUCCESS then don't need to start again.
log_failure_msg "$NAME process is running"
exit 0
fi
fi log_success_msg "Starting the process" "$prog"
daemon $prog_bin --pidfile $PIDFILE
log_success_msg "$prog process was started" }
stop()
{
echo -n $"Shutting down $prog: "
[ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown"
echo
} case "$1" in start)
start
;; stop)
stop
;; status)
status $prog
;; restart)
stop
start
;; *)
echo "Usage: $0 {start|stop|restart|status}"
;; esac
第1步:把上面的脚本放在/etc/init.d/文件夹下。
第2步:将启动脚本权限改为可执行。
chmod a+x /etc/init.d/supervisord第3步:添加启动项。
chkconfig --add supervisordchkconfig supervisord on第4步:检查是否设置成功。
chkconfig --list | grep supervisord
supervisord 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
方式二,修改/etc/rc.local脚本
1 #!/bin/sh
2 #
3 # This script will be executed *after* all the other init scripts.
4 # You can put your own initialization stuff in here if you don't
5 # want to do the full Sys V style init stuff.
6
7 #touch /var/lock/subsys/local
8 echo "hello linux" >> /tmp/hello2.log
9
10 influxd > /tmp/influxd.log 2>&1 &
11
12 echo "hello linux" >> /tmp/hello3.log
转自:https://www.cnblogs.com/ouruola863/p/8573374.html
linux 启动过程以及如何将进程加入开机自启的更多相关文章
- Linux启动过程详解(inittab、rc.sysinit、rcX.d、rc.local)
启动第一步--加载BIOS 当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的重要,以至于计算机必须在最开始就找到它.这是因为BIOS中包含了CPU的相关信息.设备启动顺序信息.硬 ...
- Linux启动过程详解
Linux启动过程详解 附上两张图,加深记忆 图1: 图2: 第一张图比较简洁明了,下面对第一张图的步骤进行详解: 加载BIOS 当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的 ...
- Linux启动过程详述
http://www.ibm.com/developerworks/cn/linux/kernel/startup/index.html Linux启动第1步:引导内核 Linux启动第2步:内核部分 ...
- Linux启动过程简述
Linux启动过程: 图片来自:https://www.cnblogs.com/codecc/p/boot.html 简单来讲: 加载BIOS–>读取MBR–>Boot Loader–&g ...
- Linux 启动过程详解
目录 1. Linux启动过程 2. 启动过程概述 3. 引导加载阶段 4. 内核阶段 4.1 内核加载阶段 4.2 内核启动阶段 5. 早期的用户空间 6. 初始化过程 6.1 SysV init ...
- 转-Linux启动过程详解(inittab、rc.sysinit、rcX.d、rc.local)
http://blog.chinaunix.net/space.php?uid=10167808&do=blog&id=26042 1)BIOS自检2)启动Grub/Lilo3)加 ...
- Linux启动过程笔记
Linux启动过程 1.启动流程(BIOS->MBR:Boot Code->引导GRUB->载入内核->运行init->runlevel) 2./boot/grub/下有 ...
- 深入理解Linux启动过程
深入理解Linux启动过程 本文详细分析了Linux桌面操作系统的启动过程,涉及到BIOS系统.LILO 和GRUB引导装载程序,以及bootsect.setup.vmlinux等映像文件 ...
- 嵌入式Linux启动过程中的问题积累
嵌入式Linux启动过程中的问题积累 Dongas 07-12-19 1.Bad Magic Number ## Booting image at 33000000 ... Bad Magic Num ...
随机推荐
- 重学VUE——vue 常用指令有哪些?
一.什么是指令? 在 vue 中,指令以 v- 开头,是一种特殊的自定义行间属性.指令属性的预期值是一个表达式,指令的职责就是:表达式的值改变时,相应地将某些行为应用到DOM上.只有v-for是一个类 ...
- 我下载了python所有包,用以备份,有需要的自提
1.背景 我最近准备把1985年-2019年的全国30m分辨率土地利用数据按照地级市进行裁剪与归纳,这需要用到Geopandas对shp数据进行批量操作.在安装Geopandas的python包时,遇 ...
- webpack learn2-vue的jsx写法和postcss 1
首先输入命令安装 npm i postcss-loader autoprefixer babel-loader babel-core 在根目录创建文件 .babelrc和postcss.config. ...
- linux centos windows服务器修改数据库最大连接数的方法
1.可查询数据库最大连接数 show variables like '%max_connections%'; 2.修改数据库最大连接数,最大限制上限为16384. 找到数据库配置文件my.cnf,在配 ...
- Orchard Core 简介
Orchard Core 是基于ASP.NET Core 对Orchard CMS的 二次开发. Orchard Core由两部分组成: Orchard Core Framework: 一个基于ASP ...
- 告别Kafka Stream,让轻量级流处理更加简单
一说到数据孤岛,所有技术人都不陌生.在 IT 发展过程中,企业不可避免地搭建了各种业务系统,这些系统独立运行且所产生的数据彼此独立封闭,使得企业难以实现数据共享和融合,并形成了"数据孤岛&q ...
- 浏览器+css基础+选择器+权重+匹配规则
浏览器的组成: shell+内核 shell:用户能看得到的界面就叫shell 内核:渲染rendering引擎和js引擎 现在主流拥有自己开发内核的浏览器:opera现在属于360和昆仑万维 CSS ...
- 初探DispatcherServlet#doDispatch
初探DispatcherServlet#doDispatch 写在前面 SpringBoot其实就是SpringMVC的简化版本,对于request的处理流程大致是一样的, 都要经过Dispatche ...
- urllib2获取CGI请求的数据
import urllib.request as urllib2 headers = { 'Authorization': 'Basic YWRtaW46YWRtaW4=', }#需要身份验证时,在请 ...
- Python代码阅读(第8篇):列表元素逻辑判断
Python 代码阅读合集介绍:为什么不推荐Python初学者直接看项目源码 本篇阅读的三份代码的功能分别是判断列表中的元素是否都符合给定的条件:判断列表中是否存在符合给定的条件的元素:以及判断列表中 ...