systemd

[转帖]LINUX PID 1 和 SYSTEMD

橙三吉。 提交于 2019-12-06 10:10:25
LINUX PID 1 和 SYSTEMD 2017年07月16日 陈皓 评论 46 条评论 57,176 人阅读 https://coolshell.cn/articles/17998.html 写的挺好的 这也是这么多年来 我第一次跟新技术的潮流差距不超过五年.. 要说清 SystemD,得先从Linux操作系统的启动说起。Linux 操作系统的启动首先从 BIOS 开始,然后由 Boot Loader 载入内核,并初始化内核。内核初始化的最后一步就是启动 init 进程。这个进程是系统的第一个进程,PID 为 1,又叫超级进程,也叫根进程。它负责产生其他所有用户进程。所有的进程都会被挂在这个进程下,如果这个进程退出了,那么所有的进程都被 kill 。如果一个子进程的父进程退了,那么这个子进程会被挂到 PID 1 下面。(注:PID 0 是内核的一部分,主要用于内进换页,参看: Process identifier ) SysV Init PID 1 这个进程非常特殊,其主要就任务是把整个操作系统带入可操作的状态。比如:启动 UI – Shell 以便进行人机交互,或者进入 X 图形窗口。传统上,PID 1 和传统的 Unix System V 相兼容的,所以也叫 sysvinit ,这是使用得最悠久的 init 实现。Unix System V 于1983年 release。

Linux服务和systemctl详解

▼魔方 西西 提交于 2019-12-06 08:50:00
定义 A Linux service is an application (or set of applications) that runs in the background waiting to be used, or carrying out essential tasks. 也就是说, Linux服务 是在后台运行的应用程序(或一组应用程序),正在等待执行或正在执行基本任务。 在Linux或者Unix系统中,服务也被称为Daemons(守护进程)。它们运行在后台,为一些程序提供服务。比如我们熟知的 sshd 服务(其中d指的就是daemon),它就是 ssh 命令的相应守护进程。 两个命令 service命令 service 命令通常用于控制服务的一些状态,其使用方法如下 Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ] 其中它会去 /etc/init.d/ 目录中寻找service_name,一些基本例子如下(为方便演示,以 sshd 为例,并且以root身份运行,因此省略了可能的 sudo ): 查看当前所有服务 , [+] 表示正在运行的, [-] 表示当前没有运行, [?] 表示因某种原因不能确定其运行状态: service -

Nginx启动错误 Failed to read PID from file /run/nginx.pid 的处理方法

谁说胖子不能爱 提交于 2019-12-06 08:45:26
问题产生原因 因为 nginx 启动需要一点点时间,而 systemd 在 nginx 完成启动前就去读取 pid file 造成读取 pid 失败 解决方法 让 systemd 在执行 ExecStart 的指令后等待一点点时间即可 如果你的 nginx 启动需要时间更长,可以把 sleep 时间改长一点 建立目录 mkdir -p /etc/systemd/system/nginx.service.d 在新建目录中建立文件override.conf,输入内容 printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf 重启 daemon 和 Nginx systemctl daemon-reload systemctl reload nginx 来源: https://www.cnblogs.com/dylan1iu/p/11973592.html

linux下如何使用systemctl管理systemd服务与单元

孤者浪人 提交于 2019-12-06 08:35:38
先来个简单总结(后面才是from的链接的内容): 启动一个服务:systemctl start postfix.service 关闭一个服务:systemctl stop postfix.service 重启一个服务:systemctl restart postfix.service 显示一个服务的状态:systemctl status postfix.service 在开机时启用一个服务:systemctl enable postfix.service 在开机时禁用一个服务:systemctl disable postfix.service 查看服务是否开机启动:systemctl is-enabled postfix.service;echo $? 查看已启动的服务列表:systemctl list-unit-files|grep enabled 说明:启用服务就是在当前“runlevel”的配置文件目录/etc/systemd/system/multi-user.target.wants/里,建立/usr/lib/systemd/system里面对应服务配置文件的软链接;禁用服务就是删除此软链接。 Systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。 Systemd是一个系统管理守护进程、工具和库的集合,用于取代System V初始进程

Linux下离线安装Docker

流过昼夜 提交于 2019-12-06 08:31:05
Linux下离线安装Docker Linux下离线安装Docker 一、基础环境 1、操作系统:CentOS 7.3 2 、 Docker 版本: 18.06.1 官方下载地址(打不开可能需要kexue上网) 3、百度云Docker 18.06.1地址: https://pan.baidu.com/s/1YdN9z72QutPkHBfLq06H1A 密码:dvvh 4 、官方参考文档: https://docs.docker.com/install/linux/docker-ce/binaries/#install-static-binaries 二、Docker安装 1、解压 tar -xvf docker-18.06.1-ce.tgz 2、将解压出来的docker文件内容移动到 /usr/bin/ 目录下 cp docker/* /usr/bin/ 3、将docker注册为service vim /etc/systemd/system/docker.service 将下列配置加到docker.service中并保存 [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld

cross-compile dbus

ぐ巨炮叔叔 提交于 2019-12-06 08:19:52
首先要交叉编译expat-2.2.0, 因为 dbus依赖 expat库。 然后,配置好 CFLAGS, LDFLAGS export CFLAGS=-I/home/charles/code/build_systemd/_install/include export LDFLAGS=-L/home/charles/code/build_systemd/_install/lib 之后,执行 configure: ./configure --host=arm-linux-gnueabi --prefix=/home/charles/code/build_systemd/_install --disable-systemd --enable-tests=no 要先 disable-systemd, 因为 systemd还没编译好,systemd也依赖于 dbus; enable-tests要去掉,因为它 需要 glib的库 来源: CSDN 作者: caspiansea 链接: https://blog.csdn.net/CaspianSea/article/details/71513894

EmuELEC系统的结构

谁说胖子不能爱 提交于 2019-12-06 08:17:54
分区结构 在img写入后, 会产生两个分区 EMUELEC: 用于启动的文件, 例如dtb文件等, 以及system.img & system.img.md5, EmuELEC的系统文件都在这个img里面 STORAGE: 空 运行中目录结构 /dev/mmcblk1p1 511.7M 373.6M 138.2M 73% /flash /dev/loop0 357.5M 357.5M 0 100% / /dev/mmcblk1p2 28.6G 3.5G 25.1G 12% /storage 启动后, EMUELEC分区被挂载为 /flash, STORAGE分区被挂载为 /storage, system.img 通过 /dev/loop0 被挂载为系统根目录 / 所以, 用户能修改的仅仅是 /flash 和 /storage 目录下的内容 root用户的home目录被定位到 /storage, 如果需要添加登录后自动执行的命令(例如添加alias), 可以直接在 /storage 目录下新建 .profile 文件来实现 系统启动的服务是通过systemd管理的, 启动脚本位于 /usr/lib/systemd/system/ 下, 因为是过loop设备挂载的, 所以这里面的文件都不可修改. 默认的启动target为 EmuELEC:/usr/lib/systemd/system

DBus 实现IPC的 配置 及流程 及 代码实现

强颜欢笑 提交于 2019-12-06 07:50:01
com.test.hello.service,安装到dbus系统目录下 [D-BUS Service] Name=com.test.hello Exec=/bin/false SystemdService=hello.service hello.service,安装到systemd下 [Unit] Description=hello [Service] Type=dbus BusName=com.test.hello ExecStart=/usr/bin/hello Restart=on-failure SuccessExitStatus=0 38 [Install] WantedBy=multi-user.target client调用代码 bool request_to_server() { GError *gerror = NULL; GDBusProxy *bproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, "com.test.hello", "/com/test/hello", "com.test.hello", NULL, &gerror); if (NULL == bproxy) { printf ("g_bus_get_sync

systemd service not starting using dbus interface

笑着哭i 提交于 2019-12-06 05:32:23
I am trying to start systemd service usnig dbus service. I am following the example 5 of below mentioned link: http://www.freedesktop.org/software/systemd/man/systemd.service.html My dbus service is: [D-BUS Service] Name=com.native.Test_Dbus_060 Exec=/usr/sbin/server_060 User=apps StandardOutput=tty TTYPath=/dev/ttyS0 SystemdService=com.native.Test_Dbus_060.service my systemd com.native.Test_Dbus_060.service is: [Unit] Description=dbus test server [Service] Type=dbus BusName=com.native.Test_Dbus_060 ExecStart=/usr/sbin/server_060 StandardOutput=tty TTYPath=/dev/ttyS0 [Install] WantedBy=multi

start request repeated too quickly

大憨熊 提交于 2019-12-06 05:06:47
问题 I'm writing a bash-script but I often face this issue. When I try to start or stop a service I often get: start request repeated too quickly How can I solve this problem? It's for example when I try to restart docker or openshift-origin master. sudo service origin-master restart ● origin-master.service - Origin Master Service Loaded: loaded (/usr/lib/systemd/system/origin-master.service; enabled; vendor preset: disabled) Active: failed (Result: start-limit) since Wed 2016-02-17 08:22:11 UTC;