[packages/linux-pstore] - initial

arekm arekm at pld-linux.org
Thu Feb 21 14:03:53 CET 2019


commit 89eac3bb7404b1fc35985399d804c376da4a535b
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Feb 21 14:03:34 2019 +0100

    - initial

 linux-pstore.crontab |  3 +++
 linux-pstore.py      | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 linux-pstore.spec    | 46 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+)
---
diff --git a/linux-pstore.spec b/linux-pstore.spec
new file mode 100644
index 0000000..a3a9cfe
--- /dev/null
+++ b/linux-pstore.spec
@@ -0,0 +1,46 @@
+Summary:	Save pstore logs and make room for future logs
+Name:		linux-pstore
+Version:	0.1
+Release:	1
+License:	GPL
+Group:		Daemons
+Source0:	%{name}.py
+Source1:	%{name}.crontab
+BuildRequires:	rpm-pythonprov
+BuildRequires:	rpmbuild(macros) >= 1.268
+Requires:	crondaemon
+Requires:	python3
+Requires:	python3-modules
+BuildArch:	noarch
+BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
+
+%description
+Copy pstore logs, report to admin and make room for future logs.
+
+%prep
+%setup -q -c -T
+
+%build
+
+%install
+rm -rf $RPM_BUILD_ROOT
+
+install -d $RPM_BUILD_ROOT{%{_sbindir},/etc/cron.d,/var/log/pstore}
+
+cp -p %{SOURCE0} $RPM_BUILD_ROOT%{_sbindir}/linux-pstore
+cp -p %{SOURCE1} $RPM_BUILD_ROOT/etc/cron.d/linux-pstore
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%post
+if [ -d /sys/fs/pstore ]; then
+	grep -qE "^none.*/sys/fs/pstore" %{_sysconfdir}/fstab || (echo -e "none\t\t/sys/fs/pstore\tpstore\tdefaults\t 0 0" >> %{_sysconfdir}/fstab && grep -q "/sys/fs/pstore" /proc/self/mounts || mount /sys/fs/pstore)
+	exit 0
+fi
+
+%files
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_sbindir}/linux-pstore
+%attr(600,root,root) /etc/cron.d/linux-pstore
+%attr(750,root,root) %dir /var/log/pstore
diff --git a/linux-pstore.crontab b/linux-pstore.crontab
new file mode 100644
index 0000000..cb4b8f1
--- /dev/null
+++ b/linux-pstore.crontab
@@ -0,0 +1,3 @@
+ at reboot		root	/usr/sbin/linux-pstore
+ at daily		root	/usr/sbin/linux-pstore
+
diff --git a/linux-pstore.py b/linux-pstore.py
new file mode 100755
index 0000000..a215d0a
--- /dev/null
+++ b/linux-pstore.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python3
+# arekm at maven.pl
+
+import datetime
+import os
+import re
+import shutil
+
+pstoredir = '/sys/fs/pstore'
+archivedir = '/var/log/pstore'
+
+os.umask(0o077)
+
+tdate = datetime.datetime.now().strftime("%Y-%m-%d")
+tdir = os.path.join(archivedir, tdate)
+
+files = sorted(os.listdir(pstoredir))
+
+if len(files) and not os.path.isdir(tdir):
+    os.mkdir(tdir)
+
+msg = "Found %d files in pstore fs directory: \n\n" % len(files)
+
+for file in files:
+    fpath = os.path.join(pstoredir, file)
+    mtime = datetime.datetime.fromtimestamp(os.path.getmtime(fpath))
+
+    msg += "File: [%s], Last modified: [%s], Contents:\n\n" % (file, mtime.strftime("%Y-%m-%d %H:%M:%S"))
+
+    mv = True
+    fdata = ""
+    try:
+        fdata = open(fpath, "rt", errors='ignore').read()
+    except Exception as e:
+        msg += "(reading contents of [%s] failed: %s)\n\n" % (file, e)
+        mv = False
+
+    try:
+        shutil.copy2(fpath, tdir)
+    except Exception as e:
+        msg += "(copying [%s] to [%s] dir failed: %s)\n\n" % (file, tdir, e)
+        mv = False
+    
+    if mv:
+        os.unlink(fpath)
+
+    if file.endswith(".z"):
+        msg += "(content compressed which usually means it is corrupted for pstore)\n\n"
+        fdata = re.sub(r'[^\x20-\x7E\n\t\r]+', lambda m: '.' * len(m.group()), fdata)
+
+    msg += fdata
+    msg += "\n\n"
+
+if len(files):
+    print(msg)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/linux-pstore.git/commitdiff/89eac3bb7404b1fc35985399d804c376da4a535b



More information about the pld-cvs-commit mailing list