Skip to content

Instantly share code, notes, and snippets.

@ksingh7
Last active February 16, 2016 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksingh7/e8f273e5988ec68eb8ac to your computer and use it in GitHub Desktop.
Save ksingh7/e8f273e5988ec68eb8ac to your computer and use it in GitHub Desktop.
CentOS7_clear_journal_error
#!/bin/python
import subprocess
cmd = "journalctl --verify"
restart_journal_service = "False"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)
out, err = p.communicate()
p_status = p.wait()
if p_status >= 1:
error_string=err.split()
for i in range(len(error_string)-1,0,-1):
temp = error_string[i]
if temp.find("Bad") > -1 or temp.find("Cannot") > -1:
remove_journal_log = "rm -rf "+error_string[i-1]
p = subprocess.Popen(remove_journal_log, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)
restart_journal_service = "True"
if restart_journal_service == "True":
p = subprocess.Popen(['systemctl','restart',' systemd-journald.service'], stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)
p_status = p.wait()
out, err = p.communicate()
if p_status == 0:
print "Journal logs cleaned"
else:
print "There was some error while cleaning journal logs"
print err
print "Journal script completed successfully"
@ksingh7
Copy link
Author

ksingh7 commented Feb 15, 2016

I wrote this patch to fix CentOS7 Journal problem

[root@ceph-c3t1 ~]# journalctl --verify
000000: missing entry array
File corruption detected at /var/log/journal/ac6c0bdcea314d87b1573065b2b69d22/user-18870.journal:000000 (of 8388608 bytes, 0%).
FAIL: /var/log/journal/ac6c0bdcea314d87b1573065b2b69d22/user-18870.journal (Bad message)
000000: missing entry array
File corruption detected at /var/log/journal/ac6c0bdcea314d87b1573065b2b69d22/user-4585.journal:000000 (of 8388608 bytes, 0%).
FAIL: /var/log/journal/ac6c0bdcea314d87b1573065b2b69d22/user-4585.journal (Bad message)
PASS: /var/log/journal/ac6c0bdcea314d87b1573065b2b69d22/user-4585@ee83106b96e3411ca2c35d28b054b2ed-000000000000086d-00052b91fdbfb732.journal
PASS: /var/log/journal/ac6c0bdcea314d87b1573065b2b69d22/user-18870@aa4656ad789047eba0ee234f7f07d90b-0000000000000ddc-00052b933aa2a9a8.journal
PASS: /var/log/journal/ac6c0bdcea314d87b1573065b2b69d22/system.journal
[root@ceph-c3t1 ~]#
[root@ceph-c3t1 ~]#

[root@ceph-c4t2 ~]# journalctl --verify
6abd00: invalid object
File corruption detected at /run/log/journal/10c4a2d23c8d41bfbfa6d4d8ed8d753e/system.journal:6abd00 (of 8388608 bytes, 83%).
FAIL: /run/log/journal/10c4a2d23c8d41bfbfa6d4d8ed8d753e/system.journal (Cannot assign requested address)
[root@ceph-c4t2 ~]#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment