首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >dpkg命令第一次自动杀死,第二次工作

dpkg命令第一次自动杀死,第二次工作
EN

Unix & Linux用户
提问于 2019-12-20 14:54:40
回答 1查看 226关注 0票数 2

我有一个自制的Debian包,它可以安装两个脚本文件、两个systemd服务和一个tar文件。手工制作的保持器脚本有前置脚本、后期脚本、预脚本和postrm。

我目前遇到的问题是,当我运行dpkg --purge 时,进程会被某些东西所扼杀(我不确定是什么):

代码语言:javascript
复制
root@host:/data# dpkg --purge  
(Reading database ... 32393 files and directories currently installed.)
Removing  (

第二次运行完全相同的命令时,它运行得很好。

代码语言:javascript
复制
root@host:/data# dpkg --purge  
(Reading database ... 32393 files and directories currently installed.)
Removing  () ...
dpkg: warning: while removing , unable to remove directory '/data': Device or resource busy - directory may be a mount point?
Purging configuration files for  () ...
dpkg: warning: while removing web-chroot, unable to remove directory '/data': Device or resource busy - directory may be a mount point?
root@host:/data#

注意: /data实际上是一个挂载点,它不属于任何其他Debian包,因此dpkg尝试(但失败)删除它。这被认为是Debian实现dpkg__的预期行为。

我的问题是,why是dpkg -清除过程在第一次运行时就会被杀死吗?什么会杀死它?

我试过检查各种日志,包括:

  • /var/log/dpkg.log
  • /var/log/apt/history.log
  • /var/log/apt/term.log
  • /var/lib/dpkg/info/.* (.list,.prerm,.postrm,.preinst,.postinst)

但是,没有什么能给我任何有用的指示,说明正在发生的事情。

注意: Debian包被安装到Debian 8 32位系统上。

The详细信息:

Debian包在以下位置安装文件:

  • /~/start-fs.sh
  • /~/stop-fs.sh
  • /data/file-system_.tar.gz
  • /etc/systemd/system/file-system.service
  • /etc/systemd/system/file-system-helper.service

维护人员脚本如下:

preinst

代码语言:javascript
复制
#!/bin/bash
# Stop services if they are running and disable them
systemctl is-active --quiet file-system && systemctl stop file-system > /dev/null 2>&1 || true
sleep 1
systemctl disable --quiet file-system.service || true
systemctl is-active --quiet file-system-helper && systemctl stop file-system-helper > /dev/null 2>&1 || true
# Remove any previous tars that could share the same name as the tar artifact
rm -f /data/file-system*.tar.gz
exit 0

postinst

代码语言:javascript
复制
#!/bin/bash

error() {
    echo "$1"
    exit 1
}

# Untar the artifact in the /data directory
tar -xzf /data/file-system*.tar.gz --directory /data || error "Could not untar artifact"
# Remove tar artifact, as it has already been untarred
rm -f /data/file-system*.tar.gz
# Restart systemctl daemon to let it know about new service files
systemctl daemon-reload
# Enable service if it is not running and enable it
systemctl is-active --quiet file-system || systemctl start file-system
systemctl enable --quiet file-system.service
exit 0

prerm

代码语言:javascript
复制
#!/bin/bash 
# Stop services if they are running and disable them
systemctl is-active --quiet file-system && systemctl stop file-system.service > /dev/null 2>&1 || true
sleep 3
systemctl disable --quiet file-system.service || true
systemctl is-active --quiet file-system-helper && systemctl stop file-system-helper.service > /dev/null 2>&1 || true
exit 0

postrm

代码语言:javascript
复制
#!/bin/bash
# Remove scripts
rm -f /root/start-fs.sh
rm -f /root/stop-fs.sh
# Remove fs in data dir
rm -rf /data/file-system/
# Remove any possible leftover artifacts (shouldn't be any)
rm -f /data/file-system*.tar.gz
# Remove systemd services
rm -f /etc/systemd/system/file-system-helper.service
rm -f /etc/systemd/system/file-system.service
exit 0

当我第一次运行dpkg -s 时,它变成了half-configured,根据dpkg的意思是The package is unpacked and configuration has been started, but not yet completed for some reason.

代码语言:javascript
复制
root@host:/data# dpkg -s 
[...]
Status: purge ok half-configured
[...]

另外,如果我手动运行./prerm脚本,然后在使用dpkg -i 安装之后手动运行./postrm脚本,则包将成功卸载并正确删除文件。

EN

回答 1

Unix & Linux用户

发布于 2020-05-18 00:52:03

看起来,您正在尝试从维护脚本中重新实现dpkg应该做的事情,但是没有考虑到调用这些脚本的所有方式。

例如,在升级期间还会调用预录制和postrm!

我的建议是避免与tar跳奇怪的舞蹈,直接在.deb中提供这些文件,并停止手动删除.deb中提供的任何文件。只需在需要时让dpkg处理拆包和拆下。

然后,对于何时调用systemd的内容,您应该查看维护人员脚本流程图,无论是从Debian策略还是从各种deb- man页面(尽管这些都不太详细)。

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/558267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档