wiki:ConfigPackageDev

Version 4 (modified by jdreed, 9 years ago) (diff)

--

See http://debathena.mit.edu/config-package-dev/

NOTES

You're not support to divert Upstart scripts  http://upstart.ubuntu.com/cookbook/#symbolic-links-don-t-work-in-etc-init because symlinks aren't supposed to work. In reality, they do work, they just break inotify. The end result is that depending on how the file is moved out of the way, upstart may notice and decide to disable the job. In reality, so far it seems to work, but this snippet in the postinst (AFTER the #DEBHELPER# tag, so it runs after c-p-d) should DTRT:

        if ! status lightdm >/dev/null 2>&1; then
            # I hope this doesn't break the world.
            initctl reload-configuration
        fi

A brief discussion of the debconf-hack feature

Primarily developed for zephyr-config to workaround the bug where you choose to use Hesiod (or have DEBIAN_FRONTEND=noninteractive), it pulls in an unconfigured Hesiod, tries to restart zhm, which can't contact any zephyr servers, and exits non-zero, so the postinst fails.

$ cat debathena-zephyr-config.debconf-hack 
zephyr-clients	zephyr-clients/read_conf	boolean	true
zephyr-clients	zephyr-clients/need-servers	note	
zephyr-clients	zephyr-clients/servers	string	z1.mit.edu z2.mit.edu

This snippet (from debconf-hack.sh) is added the the postinst, postrm, and preinst.

debconf_get () {
    perl -MDebconf::Db -MDebconf::Question -e '
        Debconf::Db->load(readonly => "true");
        for $label (@ARGV) {
            if ($q = Debconf::Question->get($label)) {
                print $q->owners."\t".$q->name."\t".$q->type."\t".$q->value."\t".$q->flag("seen")."\n";
            } else {
                print "\t$label\t\t\tfalse\n";
            }
        }' -- "$@"
}

debconf_set () {
    perl -MDebconf::Db -MDebconf::Template -MDebconf::Question -e '
        Debconf::Db->load;
        while (<>) {
            chomp;
            ($owners, $label, $type, $value, $seen) = split("\t");
            @o{split(", ", $owners)} = ();
            unless ($t = Debconf::Template->get($label)) {
                next unless ($owners);
                $t = Debconf::Template->new($label, $owners[0], $type);
                $t->description("Dummy template");
                $t->extended_description("This is a fake template used to pre-seed the debconf database. If you are seeing this, something is probably wrong.");
            }
            @to{split(", ", $t->owners)} = ();
            map { $t->addowner($_) unless exists $to{$_}; } keys %o;
            map { $t->removeowner($_) unless exists $o{$_}; } keys %to;
            next unless ($q = Debconf::Question->get($label));
            $q->value($value);
            $q->flag("seen", $seen);
            @qo{split(", ", $q->owners)} = ();
            map { $q->addowner($_) unless exists $qo{$_}; } keys %o;
            map { $q->removeowner($_) unless exists $o{$_}; } keys %qo;
        }
        Debconf::Db->save;'
}

And then the postinst and postrm have:

if [ -f /var/cache/debathena-zephyr-config.debconf-save ]; then
    debconf_set </var/cache/debathena-zephyr-config.debconf-save
    rm -f /var/cache/debathena-zephyr-config.debconf-save
fi

The preinst has:

if [ ! -f /var/cache/debathena-zephyr-config.debconf-save ]; then
    debconf_get zephyr-clients/read_conf zephyr-clients/need-servers zephyr-clients/servers >/var/cache/debathena-zephyr-config.debconf-save
    debconf_set <<EOF
zephyr-clients	zephyr-clients/read_conf	boolean	true	true
zephyr-clients	zephyr-clients/need-servers	note		true
zephyr-clients	zephyr-clients/servers	string	z1.mit.edu z2.mit.edu	true
EOF
fi