title: Why is my debian postinst script not being run?
body: <p>I have made a <code>.deb</code> of my app using <a href="https://github.com/jordansissel/fpm/wiki" rel="noreferrer">fpm</a>:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Among other things, the <code>postinst</code> script is supposed to create a user for the app:</p>
  
  <pre><code>#!/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" ] &amp;&amp; . /etc/default/$APP_NAME
  
         # Sane defaults:
  
         [ -z "$SERVER_HOME" ] &amp;&amp; SERVER_HOME=/home/$APP_NAME
         [ -z "$SERVER_USER" ] &amp;&amp; SERVER_USER=$APP_NAME
         [ -z "$SERVER_NAME" ] &amp;&amp; SERVER_NAME=""
         [ -z "$SERVER_GROUP" ] &amp;&amp; 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&gt;/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&gt;/dev/null || true
           echo "..done"
         fi
  
         # … and a bunch of other stuff.
  </code></pre>
  
  <p>It seems like the <code>postinst</code> script is being called with <code>configure</code>, but not with <code>install</code>, and I am trying to understand why. In <code>/var/log/dpkg.log</code>, I see the lines I would expect:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I checked that <code>/etc/default/myapp</code> does not exist. The file <code>/var/lib/dpkg/info/myapp.postinst</code> exists, and if I run it manually with <code>install</code> as the first parameter, it works as expected.</p>
  
  <p>Why is the <code>postinst</code> script not being run with <code>install</code>? What can I do to debug this further?</p>