[Linux]systemd和sysV

 

转自:https://www.cnblogs.com/EasonJim/p/7168216.html

在Debian8中systemd和sysVinit同时存在,NTP就是在/etc/init.d/ntp中启动

首先了解以下Ubuntu运行级别(init)对应工具的变化历史:

1、Ubuntu 6.10及以前版本使用Sysvinit。

2、Ubuntu 14.10及以前版本使用Upstart但是还留着Sysvinit并存。

https://wiki.ubuntu.com/Upstart

https://help.ubuntu.com/community/UpstartHowto

3、Ubuntu 15.04开始预设使用Systemd,但是可以在开机选项选择使用Systemd或Upstart,但是不可同時使用Sysvinit或Upstart并存。

https://wiki.ubuntu.com/SystemdForUpstartUsers

整个Linux的init发展历史:

https://zh.wikipedia.org/wiki/Init

详细介绍三个体系:Sysvinit、Upstart、Systemd

Sysvinit:https://www.ibm.com/developerworks/cn/linux/1407_liuming_init1/index.html

Upstart:https://www.ibm.com/developerworks/cn/linux/1407_liuming_init2/index.html

Systemd:https://www.ibm.com/developerworks/cn/linux/1407_liuming_init3/index.html

总结Sysvinit:

对于其它两项在Ubuntu上已经有介绍其使用方法,主要是Sysvinit比较历史悠久,其主要就是一个Shell脚本,并且是放置在/etc/init.d文件夹下。然后通过update-rc.d命令进行运行级别的操作来达到服务的启动。下面是一些服务脚本的编写参考:

其实系统提供的说明文档,在/etc/init.d/README

https://gist.github.com/naholyr/4275302

https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

来自:stackexchange的回答

chaos' answer is what some documentation says. But it's not what systemd actually does. (It's not what van Smoorenburg rc did, either. The van Smoorenburg rc most definitely did not ignore LSB headers, which insserv used to calculate static orderings, for starters.) The Freedesktop documentation, such as that "Incompatibilities" page, is in fact wrong, on these and other points. (The HOME environment variable in fact is often set, for example. This went wholly undocumented anywhere for a long time. It's now documented in the manual, at least, but that Freedesktop WWW page still hasn't been corrected.)

The native service format for systemd is the service unit. systemd's service management proper operates solely in terms of those, which it reads from one of nine directories where (system-wide) .service files can live. /etc/systemd/system/run/systemd/system/usr/local/lib/systemd/system, and /usr/lib/systemd/system are four of those directories.

The compatibility with van Smoorenburg rc scripts is achieved with a conversion program, named systemd-sysv-generator. This program is listed in the /usr/lib/systemd/system-generators/directory and is thus run automatically by systemd early in the bootstrap process at every boot, and again every time that systemd is instructed to re-load its configuration later on.

This program is a generator, a type of ancillary utility whose job is to create service unit files on the fly, in a tmpfs where three more of those nine directories (which are intended to be used only by generators) are located. systemd-sysv-generator generates the service units that run the van Smoorenburg rc scripts from /etc/init.d, if it doesn't find a native systemd service unit by that name already existing in the other six locations.

systemd service management only knows about service units. These automatically (re-)generated service units are written to invoke the van Smoorenburg rc scripts. They have, amongst other things:

[Unit]
SourcePath=/etc/init.d/wibble
[Service]
ExecStart=/etc/init.d/wibble start
ExecStop=/etc/init.d/wibble stop

Received wisdom is that the van Smoorenburg rc scripts must have an LSB header, and are run in parallel without honouring the priorities imposed by the /etc/rc?.d/ system. This is incorrect on all points.

In fact, they don't need to have an LSB header, and if they do not systemd-sysv-generator can recognize the more limited old RedHat comment headers (description:pidfile:, and so forth). Moreover, in the absence of an LSB header it will fall back to the contents of the /etc/rc?.dsymbolic link farms, reading the priorities encoded into the link names and constructing a before/after ordering from them, serializing the services. Not only are LSB headers not a requirement, and not only do they themselves encode before/after orderings that serialize things to an extent, the fallback behaviour in their complete absence is actually significantly non-parallelized operation.

The reason that /etc/rc3.d didn't appear to matter is that you probably had that script enabled via another /etc/rc?.d/ directory. systemd-sysv-generator translates being listed in any of /etc/rc2.d//etc/rc3.d/, and /etc/rc4.d/ into a native Wanted-By relationship to systemd's multi-user.target. Run levels are "obsolete" in the systemd world, and you can forget about them.

[转帖][Linux]systemd和sysV的更多相关文章

  1. [转帖]Linux systemd 常用命令

    Linux systemd 常用命令 https://www.cnblogs.com/tsdxdx/p/7288490.html systemctl hostnamectl timedatectl l ...

  2. [Linux]systemd和sysV

    转自:https://www.cnblogs.com/EasonJim/p/7168216.html 在Debian8中systemd和sysVinit同时存在,NTP就是在/etc/init.d/n ...

  3. Linux systemd 打开调试终端、添加开机自运行程序

    /************************************************************************* * Linux systemd 打开调试终端.添加 ...

  4. Linux Systemd——在RHEL/CentOS 7中启动/停止/重启服务

    RHEL/CentOS 7.0中一个最主要的改变,就是切换到了systemd.它用于替代红帽企业版Linux前任版本中的SysV和Upstart,对系统和服务进行管理.systemd兼容SysV和Li ...

  5. Linux systemd资源控制初探

    Linux systemd资源控制初探 本文记录一次cgroup子目录丢失问题,并简单探索了Linux systemd的资源控制机制. 问题现象 我们希望通过systemd拉起服务并通过cgroup限 ...

  6. linux systemd 从简单的例子入门

    linux systemd 从简单的例子入门 网上很多相关链接,一上来就给一大堆命令和讲解,让人头都大. 我们希望有一个service(服务),让它在开机启动的时候就执行. 用 root 登陆以后: ...

  7. [转帖]LINUX PID 1 和 SYSTEMD

    LINUX PID 1 和 SYSTEMD 2017年07月16日 陈皓 评论 46 条评论  57,176 人阅读 https://coolshell.cn/articles/17998.html ...

  8. linux systemd详解

    CentOS 7 使用systemd替换了SysV.Systemd目的是要取代Unix时代以来一直在使用的init系统,兼容SysV和LSB的启动脚本,而且够在进程启动过程中更有效地引导加载服务. s ...

  9. Linux Systemd 详细介绍: Unit、Unit File、Systemctl、Target

    Systemd 简介 CentOS 7 使用 Systemd 替换了SysV Ubuntu 从 15.04 开始使用 Systemd Systemd 是 Linux 系统工具,用来启动守护进程,已成为 ...

随机推荐

  1. MHA配置

    1,背景 MHA的目的在于维持MySQL Replication中Master库的高可用性,其最大特点是可以修复多个Slave之间的差异日志,最终使所有Slave保持数据一致,然后从中选择一个充当新的 ...

  2. [Linux系统] (3)应用安装方式详解(编译安装、rpm包安装、yum安装)

    软件的安装方式: 编译安装 RPM包安装 yum安装 一.编译安装 1.下载一个源码安装包:tengine-2.3.0.tar.gz.这是淘宝二次开发过的nginx.将其解压. .tar.gz 2.查 ...

  3. mysql 报错从 新安装

    卸载从新安装,综合运用 https://www.jb51.net/article/146050.htm https://www.jb51.net/article/90275.htm https://w ...

  4. IE大文件断点续传

    IE的自带下载功能中没有断点续传功能,要实现断点续传功能,需要用到HTTP协议中鲜为人知的几个响应头和请求头. 一. 两个必要响应头Accept-Ranges.ETag 客户端每次提交下载请求时,服务 ...

  5. UVa 1592 Database (map)

    题意:给出n行m列的数据库(数据范围: n 1~10000, m 1~10), 问你能不能找出两行r1, r2,使得这两行中的c1, c2列是一样的, 即(r1,c1)==(r2,c1) && ...

  6. javascript中的原型和原型链(二)

    原型(prototype) 函数的 prototype 属性(图) 每个函数都有一个prototype属性,它默认指向一个Object空对象(即称为:原型对象) 原型对象中有一个属性construct ...

  7. Angular 如何修改启动的端口

    在默认的情况下 Angular 启动使用的是端口 4200. 如果修改这个启动的端口,比如说我们希望再  4100 端口上启动? 可以在启动的时候添加端口参数 --port. 例如使用下面的启动命令: ...

  8. CentOS7 服务器上如何安装python3

    1.官网下载python3的源码包 网址:https://www.python.org/ 进去之后点击导航栏的Downloads,也可以鼠标放到Downloads上弹出菜单选择Source code, ...

  9. HDU 6136 Death Podracing (堆)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6136 题解 完了,普及题都不会做了... 发现一个重要性质是只有相邻的人才会相撞,于是直接拿堆维护即可 ...

  10. php mysql替换数据库中出现过的所有域名实现办法 (原)

    2019-10-12备注: 数据量稍微有些大且前期数据库建设相当完善的可以看一下这边的方法,数据量小或者数据库建设不完善的可以参考这篇文章,前两天看的,没自己试,有需要可以试试  https://ww ...