Skip to content

Commit fa45a45

Browse files
committed
Tidy page
1 parent 45aede0 commit fa45a45

File tree

1 file changed

+114
-104
lines changed

1 file changed

+114
-104
lines changed

docs/09-Service-management-with-SYSTEMD/03-SYSTEMD-Tools.md

+114-104
Original file line numberDiff line numberDiff line change
@@ -12,112 +12,122 @@
1212
- It can be used to manage services such as **`START/STOP/RESTART/RELOAD`** as well as **`ENABLE/DISABLE`** services
1313
during the system boot.
1414
- It is also used to **`LIST AND MANAGE UNITS`** and **`LIST AND UPDATE TARGETS`**
15-
15+
1616
![Systemctl](../../images/systemctl.png)
1717

18-
### Systemctl Commands
19-
20-
- To start a service use the start command, for example to start a docker service use **`systemctl start docker`**
21-
22-
```
23-
[~]$ systemctl start docker
24-
```
25-
26-
- To stop a service use the stop command, for example to stop a docker service use **`systemctl stop docker`**
27-
28-
```
29-
[~]$ systemctl stop docker
30-
```
31-
- To restart a service use the restart command, for example to restart a docker service use **`systemctl restart docker`** this will stop and start again.
32-
33-
```
34-
[~]$ systemctl restart docker
35-
```
36-
- To reload a service use the reload command, for example to reload a docker service use **`systemctl reload docker`**, this will reload all the configuration without interrupting the normal functionaltiy of the service
37-
38-
```
39-
[~]$ systemctl reload docker
40-
```
41-
- To enable a service and make it persistent accross reboots use the enable command, for example to enable a docker service use **`systemctl enable docker`**
42-
43-
```
44-
[~]$ systemctl enable docker
45-
```
46-
47-
- To disable a service at boot use the disable command, for example to disable a docker service use **`systemctl disable docker`** command.
48-
49-
```
50-
[~]$ systemctl disable docker
51-
```
52-
53-
- To know the status of the service use **`systemctl status docker`** command. This command provided the state of the service. If running properly is should show **`active (running)`** state as shown in screenshot below.
54-
55-
```
56-
[~]$ systemctl status docker
57-
```
58-
59-
- Besides **`active (running)`** state there are few other state that you should be aware off.
60-
61-
![Other](../../images/otherstate.PNG)
62-
63-
- Running **`systemctl daemon reload`** command after making changes to service unit file reloads the system manager configuration and makes the systemd aware of the changes.
64-
65-
- To edit the service file use command **`systemctl edit project-mercury.service --full`** this will open a text editor, you can make the changes and re-write the settings as needed, making changing this way applied immediately without running the **`systemctl daemon reload`** command
66-
67-
```
68-
[~]$ systemctl daemon-reload
69-
```
70-
```
71-
[~]$ systemctl edit project-mercury.service --full
72-
```
73-
- To see the current runlevel use **`systemctl get-default`**
74-
75-
```
76-
[~]$ systemctl get default
77-
```
78-
79-
- To change the runleve to a different target use **`systemctl set-default multi-user.target`**
80-
81-
```
82-
[~]$ systemctl set-default multi-user.target
83-
```
84-
85-
- To list all the units that systemd has loaded use **`systemctl list-units --all`**, this lists all the unit which are active, inactive or anyother state.
86-
87-
```
88-
[~]$ systemctl list-units --all
89-
```
90-
91-
- To list only active units use **`systemctl list-units`** command
92-
93-
```
94-
[~]$ systemctl list-units
95-
```
96-
97-
98-
## JOURNALCTL
99-
100-
- __Journalctl__ is a command for quering/viewing logs collected by systemd.
101-
- The systemd-journald service is responsible for systemd’s log collection, and it retrieves messages from the kernel systemd services, and other sources.
102-
- Very useful when you are troubleshooting issues with systemd services.
103-
104-
![Journalctl](../../images/journalctl.png)
105-
106-
- Using **`journalctl`** commands print all the log entries from oldest to the newest.
107-
- Using **`journalctl -b`** command print all the logs from the current boot.
108-
- Using **`journalctl -u docker.service`** command print all the logs specific to the unit specified, for example docker in this case.
109-
110-
```
111-
[~]$ journalctl
112-
```
113-
114-
```
115-
[~]$ journalctl -b
116-
```
117-
118-
```
119-
[~]$ journalctl -u docker.service
120-
```
18+
### Systemctl Commands
19+
20+
- To start a service use the start command, for example to start a docker service use **`systemctl start docker`**
21+
22+
```
23+
[~]$ systemctl start docker
24+
```
25+
26+
- To stop a service use the stop command, for example to stop a docker service use **`systemctl stop docker`**
27+
28+
```
29+
[~]$ systemctl stop docker
30+
```
31+
- To restart a service use the restart command, for example to restart a docker service use **`systemctl restart docker`** this will stop and start again.
32+
33+
```
34+
[~]$ systemctl restart docker
35+
```
36+
- To reload a service use the reload command, for example to reload a docker service use **`systemctl reload docker`**, this will reload all the configuration without interrupting the normal functionaltiy of the service
37+
38+
```
39+
[~]$ systemctl reload docker
40+
```
41+
- To enable a service and make it persistent accross reboots use the enable command, for example to enable a docker service use **`systemctl enable docker`**
42+
43+
```
44+
[~]$ systemctl enable docker
45+
```
46+
47+
- To disable a service at boot use the disable command, for example to disable a docker service use **`systemctl disable docker`** command.
48+
49+
```
50+
[~]$ systemctl disable docker
51+
```
52+
53+
- To know the status of the service use **`systemctl status docker`** command. This command provided the state of the service. If running properly is should show **`active (running)`** state as shown in screenshot below.
54+
55+
```
56+
[~]$ systemctl status docker
57+
```
58+
59+
- Besides **`active (running)`** state there are few other state that you should be aware off.
60+
61+
![Other](../../images/otherstate.PNG)
62+
63+
- Running **`systemctl daemon reload`** command after making changes to service unit file reloads the system manager configuration and makes the systemd aware of the changes.
64+
65+
- To edit the service file use command **`systemctl edit project-mercury.service --full`** this will open a text editor, you can make the changes and re-write the settings as needed, making changing this way applied immediately without running the **`systemctl daemon reload`** command
66+
67+
```
68+
[~]$ systemctl daemon-reload
69+
[~]$ systemctl edit project-mercury.service --full
70+
```
71+
- To see the current runlevel use **`systemctl get-default`**
72+
73+
```
74+
[~]$ systemctl get default
75+
```
76+
77+
- To change the runleve to a different target use **`systemctl set-default multi-user.target`**
78+
79+
```
80+
[~]$ systemctl set-default multi-user.target
81+
```
82+
83+
- To list all the units that systemd has loaded use **`systemctl list-units --all`**, this lists all the unit which are active, inactive or anyother state.
84+
85+
```
86+
[~]$ systemctl list-units --all
87+
```
88+
89+
- To list only active units use **`systemctl list-units`** command
90+
91+
```
92+
[~]$ systemctl list-units
93+
```
94+
95+
- To view, and also locate a unit file use **`systemctl cat`** command. A comment line containing the path to the unit file is printed as the first line of output.
96+
97+
```
98+
[~]$ systemctl cat project-mercury.service
99+
```
100+
101+
## JOURNALCTL
102+
103+
- __Journalctl__ is a command for quering/viewing logs collected by systemd.
104+
- The systemd-journald service is responsible for systemd’s log collection, and it retrieves messages from the kernel systemd services, and other sources.
105+
- Very useful when you are troubleshooting issues with systemd services.
106+
107+
![Journalctl](../../images/journalctl.png)
108+
109+
- Using **`journalctl`** commands print all the log entries from oldest to the newest.
110+
111+
```
112+
[~]$ journalctl
113+
```
114+
- Using **`journalctl -b`** command print all the logs from the current boot.
115+
116+
```
117+
[~]$ journalctl -b
118+
```
119+
- Using **`journalctl -u docker.service`** command print all the logs specific to the unit specified, for example docker in this case.
120+
121+
```
122+
[~]$ journalctl -u docker.service
123+
```
124+
125+
- Using **`journalctl -u docker.service --since`** command print all the logs specific to the unit specified since the given time, for example docker in this case.
126+
127+
```
128+
[~]$ journalctl -u docker.service --since "2022-01-01 13:45:00"
129+
```
130+
121131
## HANDS-ON LABS
122132
123133
- Now lets troubleshoot and help **`Bob`** [Let's Help Bob](https://kodekloud.com/courses/the-linux-basics-course/lectures/17074647)

0 commit comments

Comments
 (0)