Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dpkg: How to use trigger?

Tags:

I have written a little cdn server that shall rebuild his pool registry if new stuff (pool-content-packages) is installed into the pool.

Instead that every pool-content-package call the init.d of the cdn-server, I'd like to use triggers. Than it would restarted the server only one time at end of an installation run after all packages are installed.

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

like image 382
TLindig Avatar asked Mar 07 '13 16:03

TLindig


1 Answers

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

like image 152
TLindig Avatar answered Sep 28 '22 15:09

TLindig