我使用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
运行?我应该如何进一步调试呢?
configure
和install
中运行 _preinst_。《保护 Debian 手册》实际上提到了 "preinst 或 postinst",所以它们的示例必须是针对 preinst 的。我会尝试重新排列一下。 - Vebjorn Ljosapostinst
在安装后运行,可能只是在特定情况下。我正在Debian服务器上安装phpMyAdmin,尽管安装成功,但由于其postinst
脚本的结果而失败。这导致apt-get
认为它没有正确安装。一旦我调整了/var/lib/dpkg/info/phpmyadmin.postinst
,它就可以工作了。此外,我的系统有277个postinst
和仅75个preinst
,在安装后运行脚本似乎更受欢迎,而不是在删除之后。也许这只是一个维护不良的软件包。 - Blieque