-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpersist_journal.py
More file actions
57 lines (46 loc) · 1.57 KB
/
persist_journal.py
File metadata and controls
57 lines (46 loc) · 1.57 KB
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
#! /usr/bin/env python3
import os
import subprocess as sp
import configparser
def info(s: str):
print(f"[ INFO ] \033[92m{s}\033[0m")
if __name__ == "__main__":
if os.getuid() != 0:
print("This script needs sudo")
exit(1)
info("Setting journalctl to keep as many logs as possible")
sp.run(
[
"sudo",
"cp",
"/etc/systemd/journald.conf",
"/etc/systemd/journald.conf.bak",
]
)
journal_config = configparser.ConfigParser()
journal_config.optionxform = lambda optionstr: optionstr
journal_config.read("/etc/systemd/journald.conf")
journal_config["Journal"]["Storage"] = "persistent"
# journal_config["Journal"]["MaxFileSec"] = "180day"
journal_config["Journal"]["SystemMaxFiles"] = "200"
journal_config["Journal"]["SystemMaxUse"] = "50G"
ok = (
input(
"After this change, journalctl will save at most "
+ journal_config["Journal"]["SystemMaxFiles"]
+ " entries and use at most "
+ journal_config["Journal"]["SystemMaxUse"]
+ " of space. "
+ "Continue? [y/n] "
)
== "y"
)
if not ok:
print("Exiting.")
exit(1)
with open("/etc/systemd/journald.conf", "w") as f:
journal_config.write(f)
sp.run(["sudo", "systemctl", "daemon-reload"])
sp.run(["sudo", "systemctl", "restart", "systemd-journald"])
info("Journal service has been restarted with the new config!")
info("The backup config is at /etc/systemd/journald.conf.bak")