为什么我的debian postinst脚本没有运行?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么我的debian postinst脚本没有运行?相关的知识,希望对你有一定的参考价值。
我使用.deb
制作了我的应用程序的fpm:
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
一起运行?我该怎么做才能进一步调试?
我认为您复制的示例脚本完全错误。 postinst
不应该用任何install
或upgrade
论证来调用。 dpkg格式的权威定义是Debian Policy Manual。当前版本描述了postinst
中的chapter
6,并且仅列出configure
,abort-upgrade
,abort-remove
,abort-remove
和abort-deconfigure
作为可能的第一个参数。
我对我的答案没有完全的信心,因为你的坏榜样仍然在debian.org上,并且很难相信这样的错误可能会漏掉。
我相信Alan Curry提供的答案是错误的,至少在2015年及以后。
你的软件包的构建方式或postinst
文件中的错误导致你的问题一定有问题。
您可以通过在命令行中添加-D
(debug)选项来调试安装,即:
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
脚本将始终运行。可能会让你失望的一件事是,“旧”版本的postrm
脚本,如果升级包,将在你当前的包preinst
脚本之后运行,如果你没有意识到发生了什么,这可能会造成严重破坏。
在dpkg手册页中:安装包括以下步骤:
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.
以上是关于为什么我的debian postinst脚本没有运行?的主要内容,如果未能解决你的问题,请参考以下文章
为啥调整应用程序的 postinst 脚本会导致应用程序图标消失?
deb包安装/卸载/升级时,preinst, postinst, prerm, postrm的执行顺序
deb包安装/卸载/升级时,preinst, postinst, prerm, postrm的执行顺序