2

I've encountered the following problem when using debconf to configure a package in Ubuntu 16.04 during installation.

More precisely, the package uses debconf to save configurations files, and right after, in the postinst script, a service is started. This service also uses a debconf module to load the configurations saved in the previous step.

However, the service started with systemd fails with the error:

debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable

From what I could find, dpkg is still accessing this file with the debconf frontend, and the service crashes when it tries to start another frontend (the environmental variable DEBIAN_HAS_FRONTEND is not passed to the service). I have tried forcing the env variable DEBIAN_HAS_FRONTEND in the script, but then other errors appear.

I think I should force starting the daemon after the dpkg process has ended, and debconf has already finished, any ideas?

1

So, I finally found the problem, I'll post it in case it is helpful for somebody in the future.

As I said, I was trying to start a service from the postinst script, and said service was trying to use debconfig to fetch some configuration parameters, but there was an error with debconf since there was already once instance running (although all the configuration was done in the config file, and not in postinst).

The problem, was then, that there was an active debconf frontend during the execution of the postinst script, while I was not using debconf. I had , however, commented the line that loads the confmodue:

# . /usr/share/debconf/confmodule

Apparently, dpkg-reconfigure (and I guess dpkg too) consider that confmodule is loaded if they match the "confmodule" string on the files (config, postinst and prerm). So, while I wasn't effectively loading confmodule, dpkg-reconfigure wasn't releasing the frontend, and that's why the service couldn't initiate another debconf instance. The solution was to simply delete that line.

1

To start off, using debconf in a standalone program feels wrong. To quote man debconf-devel, section OTHER SCRIPTS:

You can also use debconf in other, standalone programs. The issue to watch out for here is that debconf is not intended to be, and must not be used as a registry. This is unix after all, and programs are configured by files in /etc, not by some nebulous debconf database (that is only a cache anyway and might get blown away). So think long and hard before using debconf in a standalone program.

The same manual page also helps with your actual problem in the previous section (THE POSTINST SCRIPT):

If your postinst launches a daemon, make sure you tell debconf to STOP at the end, since debconf can become a little confused about when your postinst is done otherwise.

That is, issue db_stop before launching your daemon (even if it does not use debconf itself).

4
  • Would you suggest using another program to configure mine? As for the db_stop, I've tried running db_stop before launching my daemon, but with no success, debconf does not stop immediately.
    – joacomug
    Jul 4 '16 at 10:21
  • You should configure your program with debconf in the config and the postinst scripts of the package. Don't use debconf in your program. Jul 4 '16 at 11:13
  • That's what I do, except I read the configurations from my program, so I have to load the confmodule. I don't make any modifications. And another issue: if I don't load confmodule in the ponstinst script, I cannot configure my program during installation, but I can if I do dpkg-reconfigure. Maybe dpkg -i does not run the config script?
    – joacomug
    Jul 4 '16 at 11:25
  • Ask questions in your config script, save the answers into config files in your postinst, and don't use debconf in your program: use the config files written by your postinst. Yes, dpkg runs the config script through the postinst, that's one of the reasons why it must include the confmodule. Please read man debconf-devel, down to the HACKS section. Jul 4 '16 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.