Score:1

systemctl not available while building packages in 22.04?

ph flag

My build server works great, but for items that try to use certain commands in their postinst script, it fails.

The current one I have an issue with is systemctl.

I have a project named iplock which is a dependency of another project (snapwebsites) and it includes a service named ipload. So I have to start that separate service manually and for that I run the following in iplock.postinst:

systemctl enable ipload
if ! systemctl start ipload
then
    echo "ERROR: the ipload command failed to load the firewall on installation."
fi

The resulting error:

/var/lib/dpkg/info/iplock.postinst: 110: systemctl: not found
dpkg: error processing package iplock (--configure):
  installed iplock package post-installation script subprocess returned error exit status 127

It looks like the build system does not install systemctl so the command fails when trying to build snapwebsites.

What am I supposed to do?

I checked the debhelper scripts. Maybe we are supposed to use the deb-systemd-helper perl script? I don't like the idea of having to test whether I'm installing for real or within the build system. Could it be that I'm missing a dependency? Although the deb-systemd-helper seems to do it properly for other services (those that have the same name as the project install as expected in the build system chrooted environment, which you get running debuild).

ru flag
Are you using a chroot build env? Because that won't give you `systemctl` typically. Also, typically, anything that *depends* on the program being installed should be in your postinst file not in your rules / DH scripts
muru avatar
us flag
"It look like the build system does not install systemctl so the command fails." ... what's the actual error that you get?
ph flag
@ThomasWard I made an update as there are multiple projects involved. The `ipload` service is part of a dependency. In regard to the `chroot`, that's what `debuild` uses. I don't create another one.
ph flag
@muru I added the error message. It just says that the `systemctl` command does not exist (not found).
ru flag
Use full paths for `systemctl` - get that from `which systemctl` on your system before executing. Note that postinst doesn't inherit $PATH from your system / runtime system so using full paths to executables is advised.
Score:1
ph flag

I found out that there is an override that can be used for this purpose:

override_dh_installsystemd:
    dh_installsystemd
    dh_installsystemd --name=ipload

Note that you need a compatibility level of 12 or more for this override to kick in (i.e. the value in debian/compat must be at least 12).

Using this technique, the service gets installed, enabled, started if systemd is present, all of that all under the hood. If systemd is not present, as in a build system, then nothing happens.

Note 1: the first dh_installsystemd installed the ipwall which is handled as a default systemd service.

Note 2: the second dh_installsystemd requires the .service file to be named iplock.ipload.service. The iplock part is the package in which that service is to be added. This technique can also be used to add multiple services within one single package.

For more info, I suggest reading the dh_installsystemd man page and do further searches on that command.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.