7

fpm.debを使用してアプリを作成しました:

fpm -s dir -t deb -n myapp -v 9 -a all -x "*.git" -x "*.bak" -x "*.orig" \
--after-remove debian/postrm  --after-install debian/postinst \
--description "Automated build." -d mysql-client -d python-virtualenv home

とりわけ、postinstスクリプトはアプリのユーザーを作成することになっています。

#!/bin/sh

    set -e

    APP_NAME=myapp

    case "$1" in
        configure)
            virtualenv /home/$APP_NAME/local
            #supervisorctl start $APP_NAME
        ;;

    # http://www.debian.org/doc/manuals/securing-debian-howto/ch9.en.html#s-bpp-lower-privs
       install|upgrade)

       # If the package has default file it could be sourced, so that
       # the local admin can overwrite the defaults

       [ -f "/etc/default/$APP_NAME" ] && . /etc/default/$APP_NAME

       # Sane defaults:

       [ -z "$SERVER_HOME" ] && SERVER_HOME=/home/$APP_NAME
       [ -z "$SERVER_USER" ] && SERVER_USER=$APP_NAME
       [ -z "$SERVER_NAME" ] && SERVER_NAME=""
       [ -z "$SERVER_GROUP" ] && SERVER_GROUP=$APP_NAME

       # Groups that the user will be added to, if undefined, then none.
       ADDGROUP=""

       # create user to avoid running server as root
       # 1. create group if not existing
       if ! getent group | grep -q "^$SERVER_GROUP:" ; then
          echo -n "Adding group $SERVER_GROUP.."
          addgroup --quiet --system $SERVER_GROUP 2>/dev/null ||true
          echo "..done"
       fi
       # 2. create homedir if not existing
       test -d $SERVER_HOME || mkdir $SERVER_HOME
       # 3. create user if not existing
       if ! getent passwd | grep -q "^$SERVER_USER:"; then
         echo -n "Adding system user $SERVER_USER.."
         adduser --quiet \
                 --system \
                 --ingroup $SERVER_GROUP \
                 --no-create-home \
                 --disabled-password \
                 $SERVER_USER 2>/dev/null || true
         echo "..done"
       fi

       # … and a bunch of other stuff.

postinstスクリプトは で呼び出されているようですが、 では呼び出されてconfigureいないようです。そのinstall理由を理解しようとしています。には/var/log/dpkg.log、次のような行が表示されます。

2012-06-30 13:28:36 configure myapp 9 9
2012-06-30 13:28:36 status unpacked myapp 9
2012-06-30 13:28:36 status half-configured myapp 9
2012-06-30 13:28:43 status installed myapp 9

/etc/default/myapp存在しないことを確認しました。ファイルが存在し、最初のパラメーターとして/var/lib/dpkg/info/myapp.postinst手動で実行すると、期待どおりに機能します。install

postinstでスクリプトが実行されないのはなぜinstallですか? これをさらにデバッグするにはどうすればよいですか?

4

3 に答える 3

18

コピーしたサンプル スクリプトは単純に間違っていると思います。or引数でpostinst呼び出すことは想定されていません。dpkg 形式の正式な定義は、Debian ポリシー マニュアルです。現在のバージョンは第 6 章で説明されており、可能な限り最初の引数として、、、 のみがリストされています。installupgradepostinstconfigureabort-upgradeabort-removeabort-removeabort-deconfigure

あなたの悪い例はまだdebian.orgにあり、そのようなバグがすり抜けるとは信じがたいので、私は私の答えに完全な自信を持っていません.

于 2012-07-04T05:05:05.640 に答える
4

少なくとも 2015 年以降の時点では、Alan Curry が提供した回答は正しくないと思います。
パッケージのビルド方法に問題があるかpostinst、問題の原因となっているファイルにエラーがあるはずです。コマンドラインに (debug) オプションを
追加することで、インストールをデバッグできます。-D

sudo dpkg -D2 -i yourpackage_name_1.0.0_all.deb

-D2この種の問題を整理する必要があります

レコードのデバッグ レベルは次のとおりです。

          Number   Description
               1   Generally helpful progress information
               2   Invocation and status of maintainer scripts
              10   Output for each file processed
             100   Lots of output for each file processed
              20   Output for each configuration file
             200   Lots of output for each configuration file
              40   Dependencies and conflicts
             400   Lots of dependencies/conflicts output
           10000   Trigger activation and processing
           20000   Lots of output regarding triggers
           40000   Silly amounts of output regarding triggers
            1000   Lots of drivel about e.g. the dpkg/info dir
            2000   Insane amounts of drivel

installコマンドはconfigureオプションを呼び出し、私の経験では、スクリプトpostinstは常に実行されます。つまずくかもしれないことの 1 つはpostrm、パッケージをアップグレードする場合、「古い」バージョンのスクリプトが現在のパッケージスクリプトのpreinstに実行されることです。
dpkg の man ページから: インストールは次の手順で構成されます。

          1. Extract the control files of the new package.

          2.  If  another version of the same package was installed before
          the new installation, execute prerm script of the old package.

          3. Run preinst script, if provided by the package.

          4. Unpack the new files, and at the same time back  up  the  old
          files, so that if something goes wrong, they can be restored.

          5.  If  another version of the same package was installed before
          the new installation, execute the postrm script of the old pack‐
          age.  Note that this script is executed after the preinst script
          of the new package, because new files are written  at  the  same
          time old files are removed.

          6.  Configure the package. 

          Configuring consists of the following steps:

          1.  Unpack  the  conffiles, and at the same time back up the old
          conffiles, so that they can be restored if something goes wrong.

          2. Run postinst script, if provided by the package.
于 2016-03-20T09:10:43.590 に答える