About the Systemd

简介: It has been a long time that the linux use `init` to manage the startup process, such as `sudo /etc/init.d/apache2 start` or `service apache2 start`, but the `init` is serial. To address this issue, the `systemd` was born. The d is the abbreviation of `daemon`, which means the `systemd` is a daemon

This article is also posted on my blog, feel free to check the latest revision: About the Systemd

It has been a long time that the linux use init to manage the startup process, such as sudo /etc/init.d/apache2 start or service apache2 start, but the init is serial. To address this issue, the systemd was born. The d is the abbreviation of daemon, which means the systemd is a daemon manager. The systemd substitutes the initd and becomes the default main process PID 1.

You can check the version systemctl --version.

systemctl

sudo systemctl reboot
sudo systemctl poweroff
sudo systemctl suspend

hostnamectl

Look up the host info, Architecture, Hardware, Kernel, Operating System, etc.

You can also query via uname -a.

timedatectl

Query the timezone.

loginctl

Manage the login session.

  • loginctl list-sessions
  • loginctl list-users
  • loginctl show-user

Unit

There are 12 types of units:

  • Service unit
  • Target unit which is a group of units
  • Device Unit
  • Mount Unit
  • Automount Unit
  • Path Unit
  • Scope Unit: not started by systemd
  • Slice Unit: process group
  • Snapshot Unit: Systemd snapshot, can switch back to a snapshot
  • Socket Unit: process communication socket
  • Swap Unit: swap file
  • Timer Unit

You can also query them:

  • systemctl list-units --all
  • systemctl list-units --all --state=inactive
  • systemctl list-units --type=service

systemctl status

  • systemctl status bluetooth.service

systemctl about service

  • systemctl start
  • systemctl stop
  • systemctl restart
  • systemctl reload
  • systemctl enable
  • systemctl disable
  • systemctl show service

Unit config

The unit config file is located at /etc/systemd/system/. But most of them are the symbolic links to the real config file in /usr/lib/systemd/system/.

The systemctl enable command will create a symbolic link to the real config file in /etc/systemd/system/(if you config start on boot in the unit file, it will start on boot) And the systemctl disable command will remove the symbolic link.
Such as

sudo systemctl enable clamd@scan.service
# which is equivalent to
$ sudo ln -s '/usr/lib/systemd/system/clamd@scan.service' '/etc/systemd/system/multi-user.target.wants/clamd@scan.service'

You can list all the config files:

systemctl list-unit-files
# the tail is the kind of unit, such as service(default), socket, etc.

There are four status of the unit:

  • enabled: the unit is enabled
  • disabled: the unit is disabled
  • static: the unit is static, which only served as other unit's dependency
  • masked: the unit is banned to be enabled

Adjust file

systemctl cat atd.service can show the specific unit file.

The detail you can refer to the official document.

Once you adjust the unit file, you need to reload the systemd and restart the service:

sudo systemctl daemon-reload
sudo systemctl restart httpd.service

Target

The target is a group of units, once the target is enabled, the units in the target will be enabled.

journalctl

You can check the kernel log and the service log by only journalctl. The config file is /etc/systemd/journald.conf.

  • sudo journalctl
  • sudo journalctl -k # kernel log
  • sudo journalctl --since yesterday
  • sudo journalctl -f # follow the log
  • sudo journalctl _PID=1 # the log of the specific process
  • sudo journalctl -u # the log of the specific service

Reference

目录
相关文章
|
18天前
|
前端开发 UED 索引
React 图片灯箱组件 Image Lightbox
图片灯箱组件是一种常见的Web交互模式,用户点击缩略图后弹出全屏窗口展示大图,并提供导航功能。本文介绍了基于React框架的图片灯箱组件开发,涵盖初始化状态管理、图片加载与预加载、键盘和鼠标事件处理等常见问题及解决方案。通过`useState`和`useEffect`钩子管理状态,使用懒加载和预加载优化性能,确保流畅的用户体验。代码案例展示了组件的基本功能实现,包括打开/关闭灯箱、切换图片及键盘操作。
116 80
|
9天前
|
存储 Dart 安全
Dart 变量
Dart 中的变量声明与初始化支持类型推断和显式声明。`var` 用于类型推断,如 `var name = Bob`;也可显式指定类型,如 `String name = Bob`。Dart 强制执行空安全,防止空解引用错误,并引入可空类型(`String?`)和不可空类型(`String`)。未初始化的不可空变量必须在使用前赋值。`late` 修饰符用于延迟初始化,确保变量在首次使用时才被初始化。`final` 和 `const` 用于定义不可变变量,前者运行时确定,后者编译时确定。类型检查和转换通过 `is` 和 `as` 实现。
103 79
|
8天前
|
网络协议 网络安全 iOS开发
Mail Service and Protocol
Recently, I have been working on DNS of my domain name. And then I need to set up the mail service of my domain name. When I tried many times, I always failed to receive the mail on my phone. Suddenly, I remembered that I didn't set up IMAP service. So let's review the mail service and protocol.
185 78
|
20小时前
|
机器学习/深度学习 计算机视觉
RT-DETR改进策略【模型轻量化】| GhostNetV2:利用远距离注意力增强廉价操作
RT-DETR改进策略【模型轻量化】| GhostNetV2:利用远距离注意力增强廉价操作
75 63
RT-DETR改进策略【模型轻量化】| GhostNetV2:利用远距离注意力增强廉价操作
|
20小时前
|
机器学习/深度学习 计算机视觉
RT-DETR改进策略【模型轻量化】| 替换骨干网络为 MobileViTv1高效的信息编码与融合模块,获取局部和全局信息
RT-DETR改进策略【模型轻量化】| 替换骨干网络为 MobileViTv1高效的信息编码与融合模块,获取局部和全局信息
74 62
RT-DETR改进策略【模型轻量化】| 替换骨干网络为 MobileViTv1高效的信息编码与融合模块,获取局部和全局信息
|
20小时前
|
机器学习/深度学习 自动驾驶 计算机视觉
RT-DETR改进策略【模型轻量化】| 替换骨干网络为 GhostNet V1 基于 Ghost Module 和 Ghost Bottlenecks的轻量化网络结构
RT-DETR改进策略【模型轻量化】| 替换骨干网络为 GhostNet V1 基于 Ghost Module 和 Ghost Bottlenecks的轻量化网络结构
75 61
RT-DETR改进策略【模型轻量化】| 替换骨干网络为 GhostNet V1 基于 Ghost Module 和 Ghost Bottlenecks的轻量化网络结构
|
20小时前
|
数据采集 搜索推荐 API
小红书笔记详情 API 接口的开发、应用与收益
小红书(RED)作为国内领先的生活方式分享平台,汇聚了大量用户生成内容(UGC),尤其是“种草”笔记。小红书笔记详情API接口为开发者提供了获取笔记详细信息的强大工具,包括标题、内容、图片、点赞数等。通过注册开放平台账号、申请API权限并调用接口,开发者可以构建内容分析工具、笔记推荐系统、数据爬虫等应用,提升用户体验和运营效率,创造新的商业模式。本文详细介绍API的开发流程、应用场景及潜在收益,并附上Python代码示例。
88 61
|
18天前
|
数据挖掘 数据处理 索引
Pandas高级数据处理:多级索引
Pandas的多级索引(MultiIndex)允许在一个轴上拥有多个层次的索引,适用于分层数据处理。可通过列表或已有DataFrame创建多级索引,如按日期和股票代码索引金融数据。常见问题包括索引层级混乱、数据选择困难和聚合操作复杂,解决方法分别为检查参数顺序、使用`loc`和`xs`方法选择数据、用`groupby()`进行聚合。代码案例展示了创建、调整索引层级、选择特定数据及聚合操作。
125 83
|
10天前
|
Web App开发 网络协议 Linux
A Brief Introduction to DNS
This article is also posted on my blog, feel free refer to it for the latest revisions: [A Brief Introduction to DNS](https://blog.timerring.com/posts/a-brief-introduction-to-dns/)
194 83
A Brief Introduction to DNS
|
12天前
|
安全
Deploy Github Pages With GPG Signing
This article is also posted on my blog, feel free refer to it for the latest revisions: [Deploy Github Pages With GPG Signing](https://blog.timerring.com/posts/deploy-github-pages-with-gpg-signing)
108 70

热门文章

最新文章