triggersdebiandpkgdebhelper

dpkg: How to use trigger?


I wrote a little CDN server that rebuilds its registry pool when new pool-content-packages are installed into that registry pool.

Instead of having each pool-content-package call the init.d of the cdn-server, I'd like to use triggers. That way it would restart the server only once at the end of an installation run, after all packages were installed.

What have I to do to use triggers in my packages with debhelper support?


Solution

  • What you are looking for is dpkg-triggers.

    One solution with use of debhelper to build the debian packages is this:

    Step 1)

    Create file debian/<serverPackageName>.triggers (replace <serverPackageName> with name of your server package).

    Step 1a)

    Define a trigger that watch the directory of your pool. The content of file would be:

    interest /path/to/my/pool

    Step 1b)

    But you can also define a named trigger, which have to be fired explicit (see step 3).

    content of file:

    interest cdn-pool-changed

    The name of the trigger cdn-pool-changed is free. You can take what ever you want.

    Step 2)

    Add handler for trigger to file debian/<serverPackageName>.postinst (replace <serverPackageName> with name of your server package).

    Example:

    #!/bin/sh
    
    set -e
    
    case "$1" in
        configure)
        ;;
    
        triggered)
            #here is the handler 
            /etc/init.d/<serverPackageName> restart
        ;;
    
        abort-upgrade|abort-remove|abort-deconfigure)
        ;;
    
        *)
            echo "postinst called with unknown argument \`$1'" >&2
            exit 1
        ;;
    esac
    
    #DEBHELPER#
    
    exit 0
    

    Replace <serverPackageName> with name of your server package.

    Step 3) (only for named triggers, step 1b) )

    Add in every content package the file debian/<contentPackageName>.triggers (replace <contentPackageName> with names of your content packages).

    content of file:

    activate cdn-pool-changed

    Use same name for trigger you defined in step 1.

    More detailed Information

    The best description for dpkg-triggers I could found is "How to use dpkg triggers". The corresponding git repository with examples you can get here:

    git clone git://anonscm.debian.org/users/seanius/dpkg-triggers-example.git