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.

## Operation

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.

### no-page

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.

### disk-usage

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.

### poweroff

There are many shutdown commands under Linux, init , shutdown , poweroff, but if you have paid attention you will find the following facts.

 1 2 3 4 5 6 7 8 9  root@localhost:~ $ll which init lrwxrwxrwx. 1 root root 22 8月 22 2019 /usr/sbin/init -> ../lib/systemd/systemd root@localhost:~$ ll which poweroff lrwxrwxrwx. 1 root root 16 8月 22 2019 /usr/sbin/poweroff -> ../bin/systemctl root@localhost:~ $ll which shutdown lrwxrwxrwx. 1 root root 16 8月 22 2019 /usr/sbin/shutdown -> ../bin/systemctl  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.

### list-dependencies

systemd can specify the dependencies of a service, specified by the keywords After , Before , Requires, and the specific dependency path of the service is displayed via systemctl list-dependencies <service>.

## Configuration

### Restart

Most services are a resident process and we usually want to keep it running despite crashes, kills, abnormal interruptions, etc. So we can specify Restart=on-failure in [Servie] to accomplish this.

### TimeoutStopSec

When stopping a service via systemctl stop, if the action specified in ExecStop takes a long time, we can set the timeout by adding TimeoutStopSec=10s.

### RefuseManualStop

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:.