前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >About the Systemd

About the Systemd

原创
作者头像
timerring
发布2025-02-09 11:59:33
发布2025-02-09 11:59:33
720
举报

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

代码语言:sh
复制
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 <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 <service>
  • systemctl stop <service>
  • systemctl restart <service>
  • systemctl reload <service>
  • systemctl enable <service>
  • systemctl disable <service>
  • 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

代码语言:sh
复制
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:

代码语言:sh
复制
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:

代码语言:sh
复制
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 <service> # the log of the specific service

Reference

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • systemctl
  • hostnamectl
  • timedatectl
  • loginctl
  • Unit
    • systemctl status
    • systemctl about service
  • Unit config
    • Adjust file
  • Target
  • journalctl
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档