Three surprising things you can do with systemd
It's not just about making your computer start up faster.
When systemd first came out, there was a lot of news about how it could speed up boot times. This feature appeals to most people (less so to those who don't reboot), so in many ways, that's the reputation it still has today. While systemd does play a role in starting services in parallel during the boot process, it does much more than that. Here are three things you might not realize systemd can do, but you should take advantage of.
1. Simplify Linux ps
If you have ever used the ps
, or even just the top
command, then You will know that your computer has hundreds of processes running all the time. Sometimes, this is just the information you need to understand what your computer or its users are doing. Other times, what you really need is a general overview.
systemd-cgtop
command provides a simple view of the computer load based on the control group cgroup task schedule. Control groups are important to modern Linux and are basically the underlying support structure for containers and Kubernetes (which is why cloud computing can scale), but they are also a useful structure on a home computer. For example, from the output of systemd-cgtop
you can see the load of user processes, not system processes:
Control Group Proc+ %CPU MemoryInput/s Output/s / 1835.0 1.6G 0B 3.0M user.slice42.8 1.1G 0B 174.7K user.slice/user-1000.slice42.8 968.2M 0B 174.7K system.slice 652.2 1.5G 0B 2.8M
You can also just view your userspace Processes, or look at user space processes and kernel threads.
This is by no means a replacement for top
or ps
, but to observe you from a different and unique perspective system. It can be critical when running containers because containers use control groups.
2. Linux scheduled tasks
Cron is a classic component of Linux. You use Cron when you want to schedule something to happen on a regular basis. It's reliable and integrates into your system fairly well.
The problem is, Cron does not understand that some computers will be shut down. If you have a cron job scheduled for midnight, but you shut down your computer at 23:59 every day, your cron job will never run. Cron doesn't have any tools to detect jobs missed overnight.
As an answer to this question, there is a good one Anacron, but it is not as well integrated as Cron. To get Anacron running, you need to do a lot of setup.
The second option is systemd timers. Like Cron, it's built-in and ready to use. You need to write a unit file, which is definitely more work than a single-line Crontab entry, but it's also pretty simple. For example, here's a unit file that runs a hypothetical backup script 30 minutes after boot, but only once a day. This ensures that my computer is backed up and prevents it from trying to back up more than once a day.
[Unit] Description=Backup Requires=myBackup.service [Timer] OnBootSec=30min OnUnitActiveSec=1d [Install] WantedBy=timers.target
Of course, you can also intervene and prompt to run a task. Thanks to the OnUnitActiveSec
directive, systemd will not try to run jobs that you manually activated.
3、运行 Linux 容器
容器使启动一个复杂的服务变得非常容易。你可以在短短几分钟内运行一个 Mattermost 或 Discourse 服务器。在某些情况下,困难的部分是在你运行容器后管理和监控它们。Podman 使得管理它们变得容易,但是用什么来管理 Podman 呢?嗯,你可以使用 systemd。
Podman 有一个内置的命令来生成单元文件,这样你的容器就可以被 systemd 管理和监控:
$ podman generate systemd --new --files --name example_pod
然后你所要做的就是启动服务:
$ systemctl --user start pod-example_pod.service
和其他服务一样,systemd 确保你的容器荚在任何情况下都能运行。它记录问题,你可以用 journalctl
和其他重要的日志来查看,你也可以用 systemd-cgtop
在控制组中监控它的活动。
它不是 Kubernetes 平台,但对于一两个容器来说,你只需要在可靠和可预测的基础上提供服务,Podman 和 systemd 是一对很棒的组合。
下载 systemd 电子书
systemd 的内容还有很多,你可以从作者 David Both 的新书《systemd 实用指南》中了解基础知识,以及很多实用的技巧。
The above is the detailed content of Three surprising things you can do with systemd. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Once upon a time, when I was a fresh graduate majoring in computer science, I browsed many job postings on recruitment websites. I was confused by the dazzling technical positions: R&D engineer, operation and maintenance engineer, test engineer... During college, my professional courses were so-so, not to mention having any technical vision, and I had no clear ideas about which technical direction to pursue. Until a senior student said to me: "Do operation and maintenance. You don't have to write code every day to do operation and maintenance. You just need to be able to play Liunx! It's much easier than doing development!" I chose to believe... I have been in the industry for more than ten years , I have suffered a lot, shouldered a lot of blame, killed servers, and experienced department layoffs. If someone tells me now that operation and maintenance is easier than development, then I will

1. Introduction to SpringBootActuator endpoint 1.1 What is Actuator endpoint SpringBootActuator is a sub-project used to monitor and manage SpringBoot applications. It provides a series of built-in endpoints (Endpoints) that can be used to view the status, operation status and operation indicators of the application. Actuator endpoints can be exposed to external systems in HTTP, JMX or other forms to facilitate operation and maintenance personnel to monitor, diagnose and manage applications. 1.2 The role and function of the endpoint The Actuator endpoint is mainly used to implement the following functions: providing health check of the application, including database connection, caching,

With the rapid development of the Internet, the complexity of enterprise-level applications is increasing day by day. In response to this situation, the microservice architecture came into being. With its modularity, independent deployment, and high scalability, it has become the first choice for enterprise-level application development today. As an excellent microservice architecture, Spring Cloud has shown great advantages in practical applications. This article will introduce the deployment and operation and maintenance of SpringCloud microservice architecture. 1. Deploy SpringCloud microservice architecture SpringCloud

The term observability originates from the engineering field and has become increasingly popular in the software development field in recent years. Simply put, observability is the ability to understand the internal state of a system based on external outputs. IBM defines observability as: Generally, observability refers to the degree to which the internal state or condition of a complex system can be understood based on knowledge of its external output. The more observable the system is, the faster and more accurate the process of locating the root cause of a performance issue can be without the need for additional testing or coding. In cloud computing, observability also refers to software tools and practices that aggregate, correlate, and analyze data from distributed application systems and the infrastructure that supports their operation in order to more effectively monitor, troubleshoot, and debug application systems. , thereby achieving customer experience optimization and service level agreement

Before the holidays, I collaborated with the PG China community to conduct an online live broadcast on how to use D-SMART to operate and maintain the PG database. It happened that one of my clients in the financial industry listened to my introduction and called over to chat. They are selecting database Xinchuang and have tried several domestic databases. Finally, they are going to choose TDSQL. I felt a little surprised at the time. They had been selecting domestic databases since 2020, but it seemed that the initial experience after using TDSQL was not very good. Later, after communication, I learned that they had just started using TDSQL's distributed database and found that the research and development requirements were too high, so they all chose TDSQL's centralized MYSQL instance. After using it, they found that it was very easy to use. The entire database cloud

Through interviews and submissions, veterans in the field of operation and maintenance are invited to provide profound insights and collide together, with a view to forming some advanced consensus and promoting the industry to move forward better. In this issue, we invite Zou Yi, the operation and maintenance director of Tuyou Games. Mr. Zou often jokingly calls himself the operation and maintenance representative of the world's top 5 million companies. It can be seen that in his heart, he feels that the operation and maintenance construction ideas of small and medium-sized companies are different from those of large enterprises. There are differences. Today we have a few questions and ask Mr. Zou to share his journey of integrating research and operations for small and medium-sized companies. This is the 6th issue of the down-to-earth and high-level "Operation and Maintenance Forum", starting now! Question Preview Tuyou is a game company. What do you think are the unique features of game operation and maintenance? What are the biggest operational challenges you face? How did you solve these challenges? Game operation and maintenance people

Don’t learn golang for operation and maintenance. The reasons are: 1. Golang is mainly used to develop applications with high performance and concurrent performance requirements; 2. The tools and scripting languages commonly used by operation and maintenance engineers can already meet most management and Maintenance requirements; 3. Learning golang requires a certain programming foundation and experience; 4. The main goal of the operation and maintenance engineer is to ensure the stability and high availability of the system, not to develop applications.

Through interviews and submissions, veterans in the field of operation and maintenance are invited to provide profound insights and collide together, with a view to forming some advanced consensus and promoting the industry to move forward better. In this issue, we invite Chen Cunli, general manager of Du Xiaoman System Operation and Maintenance Department. He has spent most of his 20-year career in the Internet field. During his time in the Baidu Operations and Maintenance Department, his team members called him "Commander Chen" due to his excellent leadership style. Today we invite "Commander Chen" to talk about his views. This is the 5th issue of the down-to-earth and high-level "Operation and Maintenance Forum", starting now! Question preview: You joined Baidu very early and later became independent with Du Xiaoman. We understand that many employees around you have been following you for a long time and have experienced many business operation and maintenance tests. I believe everyone is very interested.
