atop: fix packaging .service files, add option to build with atopgpu

This commit is contained in:
Paul Schyska 2021-05-14 02:08:41 +02:00
parent 2703a7999a
commit 327dcea4cc
No known key found for this signature in database
GPG key ID: D49D4F8259DB724F
7 changed files with 113 additions and 14 deletions

View file

@ -0,0 +1,13 @@
--- a/atop-pm.sh
+++ b/atop-pm.sh
@@ -2,8 +2,8 @@
case "$1" in
- pre) /usr/bin/systemctl stop atop
+ pre) @systemd@/bin/systemctl stop atop
exit 0
;;
- post) /usr/bin/systemctl start atop
+ post) @systemd@/bin/systemctl start atop
exit 0
;;

View file

@ -0,0 +1,7 @@
--- a/atop-rotate.service
+++ b/atop-rotate.service
@@ -4,3 +4,3 @@
[Service]
Type=oneshot
-ExecStart=/usr/bin/systemctl try-restart atop.service
+ExecStart=@systemd@/bin/systemctl try-restart atop.service

View file

@ -0,0 +1,14 @@
--- a/atop.service
+++ b/atop.service
@@ -9,7 +9,8 @@
Environment=LOGPATH=/var/log/atop
-EnvironmentFile=/etc/default/atop
+EnvironmentFile=-/etc/default/atop
ExecStartPre=/bin/sh -c 'test -n "$LOGINTERVAL" -a "$LOGINTERVAL" -eq "$LOGINTERVAL"'
ExecStartPre=/bin/sh -c 'test -n "$LOGGENERATIONS" -a "$LOGGENERATIONS" -eq "$LOGGENERATIONS"'
-ExecStart=/bin/sh -c 'exec /usr/bin/atop ${LOGOPTS} -w "${LOGPATH}/atop_$(date +%%Y%%m%%d)" ${LOGINTERVAL}'
-ExecStartPost=/usr/bin/find "${LOGPATH}" -name "atop_*" -mtime +${LOGGENERATIONS} -exec rm -v {} \;
+ExecStartPre=/bin/sh -c 'mkdir -p "${LOGPATH}"'
+ExecStart=/bin/sh -c 'exec @out@/bin/atop ${LOGOPTS} -w "${LOGPATH}/atop_$(date +%%Y%%m%%d)" ${LOGINTERVAL}'
+ExecStartPost=@findutils@/bin/find "${LOGPATH}" -name "atop_*" -mtime +${LOGGENERATIONS} -exec rm -v {} \;
KillSignal=SIGUSR2

View file

@ -0,0 +1,11 @@
--- a/atopacct.service
+++ b/atopacct.service
@@ -8,6 +8,6 @@
[Service]
Type=forking
-PIDFile=/var/run/atopacctd.pid
-ExecStart=/usr/sbin/atopacctd
+PIDFile=/run/atopacctd.pid
+ExecStart=@out@/bin/atopacctd
[Install]

View file

@ -0,0 +1,9 @@
--- a/atopgpu.service
+++ b/atopgpu.service
@@ -6,5 +6,5 @@
[Service]
-ExecStart=/usr/sbin/atopgpud
+ExecStart=@out@/bin/atopgpud
Type=oneshot
RemainAfterExit=yes

View file

@ -1,4 +1,14 @@
{lib, stdenv, fetchurl, zlib, ncurses}:
{ lib
, stdenv
, fetchurl
, zlib
, ncurses
, findutils
, systemd
, python3
# makes the package unfree via pynvml
, withAtopgpu ? false
}:
stdenv.mkDerivation rec {
pname = "atop";
@ -9,31 +19,52 @@ stdenv.mkDerivation rec {
sha256 = "nsLKOlcWkvfvqglfmaUQZDK8txzCLNbElZfvBIEFj3I=";
};
buildInputs = [zlib ncurses];
nativeBuildInputs = if withAtopgpu then [ python3.pkgs.wrapPython ] else [ ];
buildInputs = [ zlib ncurses ] ++ (if withAtopgpu then [ python3 ] else [ ]);
pythonPath = if withAtopgpu then [ python3.pkgs.pynvml ] else [ ];
makeFlags = [
"SCRPATH=$out/etc/atop"
"LOGPATH=/var/log/atop"
"INIPATH=$out/etc/rc.d/init.d"
"SYSDPATH=$out/lib/systemd/system"
"CRNPATH=$out/etc/cron.d"
"DEFPATH=$out/etc/default"
"ROTPATH=$out/etc/logrotate.d"
"DESTDIR=$(out)"
"BINPATH=/bin"
"SBINPATH=/bin"
"MAN1PATH=/share/man/man1"
"MAN5PATH=/share/man/man5"
"MAN8PATH=/share/man/man8"
"SYSDPATH=/lib/systemd/system"
"PMPATHD=/lib/systemd/system-sleep"
];
patches = [
./atop-pm.sh.patch
./atop-rotate.service.patch
./atop.service.patch
./atopacct.service.patch
] ++ (if withAtopgpu then [ ./atopgpu.service.patch ] else [ ]);
preConfigure = ''
sed -e "s@/usr/@$out/@g" -i $(find . -type f )
sed -e "/mkdir.*LOGPATH/s@mkdir@echo missing dir @" -i Makefile
sed -e "/touch.*LOGPATH/s@touch@echo should have created @" -i Makefile
for f in *.{sh,service}; do
findutils=${findutils} systemd=${systemd} substituteAllInPlace "$f"
done
sed -e 's/chown/true/g' -i Makefile
sed -e '/chkconfig/d' -i Makefile
sed -e 's/chmod 04711/chmod 0711/g' -i Makefile
'';
installTargets = [ "systemdinstall" ];
preInstall = ''
mkdir -p "$out"/{bin,sbin}
mkdir -p $out/bin
'';
postInstall = ''
# remove extra files we don't need
rm -rf $out/{var,etc}
rm -rf $out/bin/atop{sar,}-${version}
'' + (if withAtopgpu then ''
wrapPythonPrograms
'' else ''
rm $out/lib/systemd/system/atopgpu.service
rm $out/bin/atopgpud
rm $out/share/man/man8/atopgpud.8
'');
meta = with lib; {
platforms = platforms.linux;

View file

@ -0,0 +1,14 @@
--- a/netatop.service
+++ b/netatop.service
@@ -7,8 +7,8 @@
[Service]
Type=oneshot
-ExecStartPre=/sbin/modprobe netatop
-ExecStart=/usr/sbin/netatopd
-ExecStopPost=/sbin/rmmod netatop
-PIDFile=/var/run/netatop.pid
+ExecStartPre=@kmod@/bin/modprobe netatop
+ExecStart=@out@/bin/netatopd
+ExecStopPost=@kmod@/bin/rmmod netatop
+PIDFile=/run/netatop.pid
RemainAfterExit=yes