Subject: bug#700: Subject: package nvidia-persistenced "not fully installed"

From: [email-masked]
Date: Tue, 9 Aug 2022 22:53:08 +0200

Package: nvidia-persistenced
Version: 470.129.06-1

date: 2022-06-16 (did not find the time to complete the report)
System: devuan version is daedalus/ceres
kernel: Linux 5.18.0-2-amd64

Abstract: There is no other error than the package's "not fully installed" status.
Traced to a "/etc/init.d/nvidia-persistenced start|restart" issue.
(Possibly, this happens only on the initial installation of nvidia driver and kernel. don't know)

* Description
The package status can be fixed without an update (see log below):
  Stop nvidia-persistenced, then call apt. Done.
  $ sudo /etc/init.d/nvidia-persistenced stop && sudo apt upgrade
Diving deeper:
During installation: First call of "/etc/init.d/nvidia-persistenced start" will exit(1).
  This is to expect and not an error (if nvidia-kernel not booted yet).
  But interpreted as "install failure".
After reboot, at any further apt invocation:
  "/etc/init.d/nvidia-persistenced start" is fired again.
  But now /usr/bin/nvidia-persistenced is already running, and returns exit(1).

* Fix proposal:
Figured out two ways - not sure which one to use:
a) $ "/usr/bin/nvidia-persistenced start" may exit(0) in case nvidia-persistenced is running
OR
b) DEBIAN/postinst may always fire "restart"

#-----------------------------------------------------------------------------#
# Patch for: /etc/init.d/nvidia-persistenced
# (recycled test condition, as used in section "stop")
#
# $ diff /etc/init.d/nvidia-persistenced  /etc/init.d/nvidia-persistenced.original
66c66
<       [ ! -z "${NVPD_PID}" ] || ${NVPD_BIN} --user ${NVPD_USER}
---
>       ${NVPD_BIN} --user ${NVPD_USER}

#-----------------------------------------------------------------------------#
# Patch for: DEBIAN/postinst  -  NOT tested
# In case patch for /etc/init.d/nvidia-persistenced is a bad idea.
#
# $ diff DEBIAN/postinst DEBIAN/postinst.original
19c19,24
< 		invoke-rc.d --skip-systemd-native nvidia-persistenced restart || exit 1
---
> 		if [ -n "$2" ]; then
> 			_dh_action=restart
> 		else
> 			_dh_action=start
> 		fi
> 		invoke-rc.d --skip-systemd-native nvidia-persistenced $_dh_action || exit 1

#-----------------------------------------------------------------------------#
# log (from reverted disk image)
#-----------------------------------------------------------------------------#
# daedalus box with multiarch i386 enabled
# initial installation of proprietary nvidia drivers
$ sudo apt-get install nvidia-driver nvidia-kernel-dkms nvidia-alternative nvidia-xconfig nvidia-settings nvidia-modprobe
$ sudo reboot

$ ps ax | grep nvidia-persistenced
 1277 ?        Ss     0:00 /usr/bin/nvidia-persistenced --user nvpd
 2432 pts/0    S+     0:00 grep nvidia-persistenced

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Setting up nvidia-persistenced (470.129.06-1) ...
Starting NVIDIA Persistence Daemon
nvidia-persistenced failed to initialize. Check syslog for more details.
invoke-rc.d: initscript nvidia-persistenced, action "start" failed.
dpkg: error processing package nvidia-persistenced (--configure):
 installed nvidia-persistenced package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 nvidia-persistenced
E: Sub-process /usr/bin/dpkg returned an error code (1)

$ sudo /etc/init.d/nvidia-persistenced stop
Stopping NVIDIA Persistence Daemon

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Setting up nvidia-persistenced (470.129.06-1) ...
Starting NVIDIA Persistence Daemon

==> when the daemon is stopped, apt succeeded
I do not know exactly how to adopt that into "postinst"
apt upgrade - to trigger package management

#-----------------------------------------------------------------------------#
# Possibly useful : daemon start and stop with extended status output
# Alternative to the patch above
# /etc/init.d/nvidia-persistenced
#
#       # start
       [ ! -z "${NVPD_PID}" ] || ${NVPD_BIN} --user ${NVPD_USER}  && echo "NVIDIA Persistence Daemon was already running"
#       # stop
       [ ! -z "${NVPD_PID}" ] && kill ${NVPD_PID} &> /dev/null    || echo "NVIDIA Persistence Daemon was not running"
#-----------------------------------------------------------------------------#

Dear maintainer,
feel free to contact me for additional information / testing / reversing. I'm not a software developer.
Regards, Thomas