blob: 18f87e5fdbbf28fb815e968087e5e0e2e11953ab (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# systemd
## systemctl
Inspect units:
```text
systemctl [opts] [cmd]
[opts]
--user
--type=TYPE List only given types eg, service, timer, socket (use --type=help for a list)
--state=STATE List only given states eg running, enabled (use --state=help for a list)
--failed List only failed services
[cmd]
list-units <pattern> List units in memory
status <unit> Show runtime status of unit
start <unit> Start a unit
stop <unit> Stop a unit
restart <unit> Restart a unit
reload <unit> Reload a unit
enable <unit> Enable a unit (persistent)
disable <unit> Disable a unit
cat <unit> Print unit file
show <unit> Show properties of unit
```
### Example: List failed units
```bash
# List all system failed units.
systemctl --failed
# List all user failed units.
systemctl --user --failed
```
### Example: Trivial user unit
```bash
# Generate unit
mkdir -p ~/.config/systemd/user
echo '[Unit]
Description=Test logger
[Service]
Type=oneshot
ExecStart=logger "Hello from test unit"' > ~/.config/systemd/user/test.service
# Run unit
systemctl --user start test
# See log message
journalctl --user -u test -n 5
```
## journalctl
Inspect journal logs:
```text
journalctl [opts] [matches]
--user Current user journal (system by default)
-u <unit> Show logs for specified <unit>
-n <lines> Show only last <lines>
-f Follow journal
-g <pattern> Grep for <pattern>
```
Cleanup:
```text
journalctl [opts]
--disk-usage Show current disk usage
--vacuum-size=<size> Reduce journal log to <size> (K/M/G)
```
## References
- [man systemd.unit(5)](https://www.man7.org/linux/man-pages/man5/systemd.unit.5.html)
- [man systemd.service(5)](https://www.man7.org/linux/man-pages/man5/systemd.service.5.html)
|