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

目录
相关文章
|
关系型数据库 Linux Apache
|
10月前
|
监控 Linux 开发者
Docker服务systemd配置文件详解
Docker服务systemd配置文件详解
427 0
|
NoSQL
systemd-coredump
systemd-coredump
306 0
|
监控 Java 数据库连接
服务--systemd的管理
服务--systemd的管理
204 0
|
Linux
Linux:systemctl、service、chkconfig
Linux:systemctl、service、chkconfig
149 0
|
运维 网络协议 关系型数据库
Systemd | 学习笔记
快速学习Systemd,掌握如何进行服务的管理和配置,并引导学生主动完成服务的编写,为后续的运维工作打下基础
Systemd | 学习笔记
systemd简介
systemd是Linux的一个工具,是CentOS7.x系统启动的第一个进程 1.systemd的一些相关命令 (1)systemctl 系统管理 #检查系统是否充分的运行 [root@localhost ~]# systemctl is-system-running r...
1497 0