learningequality / kolibri-server

A performance-boosting access layer for Kolibri with multi-core support and improved caching
4 stars 8 forks source link

Installing in a chroot envrionment gives errors #91

Open intelliant01 opened 2 years ago

intelliant01 commented 2 years ago

Have a squashfs Ubuntu 20.04 OS image which I have loop mounted and tried to update the kolibri-server package. Package - kolibri-server_0.4.0-0ubuntu2_all.deb

I got these errors -

root@server:/# apt install kolibri-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
  kolibri-server
1 upgraded, 0 newly installed, 0 to remove and 106 not upgraded.
Need to get 0 B/22.5 kB of archives.
After this operation, 2,048 B of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 421367 files and directories currently installed.)
Preparing to unpack .../kolibri-server_0.4.0-0ubuntu2_all.deb ...
Running in chroot, ignoring request.
INFO: Already stopped: Stopped
invoke-rc.d: initscript kolibri-server, action "stop" failed.
dpkg: warning: old kolibri-server package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
Running in chroot, ignoring request.
INFO: Already stopped: Stopped
invoke-rc.d: initscript kolibri-server, action "stop" failed.
dpkg: error processing archive /var/cache/apt/archives/kolibri-server_0.4.0-0ubuntu2_all.deb (--unpack):
 new kolibri-server package pre-removal script subprocess returned error exit status 1
Running in chroot, ignoring request.
Errors were encountered while processing:
 /var/cache/apt/archives/kolibri-server_0.4.0-0ubuntu2_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

The install process should have completed without any errors in the chroot envrionment.

intelliant01 commented 2 years ago

@jredrejo Only two lines in the respective files, that are being generated by the debhelper seem to be the cause of the above issue in a chroot env wherein no services are active.

Specifically the exit 1 in /var/lib/dpkg/info/kolibri-server.prerm results in the above error.

In /var/lib/dpkg/info/kolibri-server.prerm:

# Automatically added by dh_installinit/11.1.6ubuntu2
if [ -x "/etc/init.d/kolibri-server" ]; then
        invoke-rc.d kolibri-server stop || exit 1
fi
# End automatically added section

should be

# Automatically added by dh_installinit/11.1.6ubuntu2
if [ -x "/etc/init.d/kolibri-server" ]; then
        invoke-rc.d kolibri-server stop || ! ischroot && exit 1
fi
# End automatically added section

In /var/lib/dpkg/info/kolibri-server.postinst:

# Automatically added by dh_installinit/11.1.6ubuntu2
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
        if [ -x "/etc/init.d/kolibri-server" ]; then
                update-rc.d kolibri-server defaults >/dev/null
                invoke-rc.d kolibri-server start || exit 1
        fi
fi
# End automatically added section

should be

# Automatically added by dh_installinit/11.1.6ubuntu2
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
        if [ -x "/etc/init.d/kolibri-server" ]; then
                update-rc.d kolibri-server defaults >/dev/null
                invoke-rc.d kolibri-server start || ! ischroot && exit 1
        fi
fi
# End automatically added section

invoke-rc.d is inherently chroot safe i.e. it identifies a chroot and prevents execution of the "action". However, the additional exit 1 added by the dh_installinit generated code causes the termination. I tried reading up on how to override the addition of exit 1 or make it conditional with a ! ischroot, but could not find a solution.

intelliant01 commented 2 years ago

With the help of @cyberorg figured out that the root of the problem is in /etc/init.d/kolibri-server in the start and stop cases -

Detecting chroot and exiting with status 0 helps fix it -

# diff /etc/init.d/kolibri-server.old  /etc/init.d/kolibri-server
136a137
>     ischroot && exit 0
149a151
>     ischroot && exit 0

This seems to be the only feasible method because $SU_COMMAND $KOLIBRI_USER -c "$KOLIBRI_COMMAND stop" always returns an exit status 1 in chroot.