Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

debian - dpkg: How to use trigger?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...