Most Linux distributions are now managed by systemd, which is becoming more and more complex, but there are only so many common operations, so today I will talk about my own common operations and configuration.
When adding a new service to a system, it is common to keep changing the test.service configuration file. After changing the configuration file, it is usually necessary to run
systemctl daemon-reload to re-add the systemd configuration.
The service log is usually viewed using journalctl. However, when the log exceeds the maximum number of characters that can be displayed on the current line, the log is truncated by default, so you can use
journalctl -u <service> --no-page to have the log automatically folded.
The systemd journal configuration file is at
/etc/systemd/journald.conf, so if I want to see how much disk space a service’s journal is taking up, I can use the command
journalctl -u <servie> --disk-usage.
There are many shutdown commands under Linux,
poweroff, but if you have paid attention you will find the following facts.
Yes, systemd works better. systemd determines the
$0 name to execute the corresponding command, so we can execute
systemctl poweroff to shut down the machine.
systemd can specify the dependencies of a service, specified by the keywords
Requires, and the specific dependency path of the service is displayed via
systemctl list-dependencies <service>.
Most services are a resident process and we usually want to keep it running despite crashes, kills, abnormal interruptions, etc. So we can specify
[Servie] to accomplish this.
When stopping a service via
systemctl stop, if the action specified in
ExecStop takes a long time, we can set the timeout by adding
If there are services that we just want to keep up, or start automatically through a dependency, and do not want human intervention, then we can ensure that the service cannot be stopped manually by setting
RefuseManualStop=true, e.g. rdma.service:.
is similar to Requires=, except that it only acts on the stopping or restarting of a unit. The implication is that when a unit listed here is stopped or restarted, the unit itself is also stopped or restarted at the same time. Note that this dependency is unidirectional and that the stopping or restarting of the unit itself does not affect the units listed here.
If a.service contains PartOf=b.service, then this dependency will appear as ConsistsOf=a.service in the property list of b.service. That is, you cannot set the ConsistsOf= dependency directly.
Anyone who has configured openvpn on Linux will have seen examples of [
firstname.lastname@example.org](mailto:%email@example.com) such as.
If you need to start OpenVPN automatically at system boot, you can configure it by enabling openvpn@.service on the corresponding machine for both server and client. For example, if the client configuration file is /etc/openvpn/client.conf, the service name should be firstname.lastname@example.org. Or, if the server-side configuration file is /etc/openvpn/server.conf, the service name would be email@example.com.
Let’s look at the corresponding systemd configuration file.