詳細:

詳細:

2つのスクリプトファイル、2つのシステムサービス、およびtarファイルをインストールする自作のDebianパッケージがあります。手作りの管理者スクリプトには preinst、post inst、prerm、postrm があります。

現在経験している問題は、dpkg --purge <PACKAGE>プロセスを実行すると何かによってプロセスが終了することです(何かわかりません)。

root@host:/data# dpkg --purge <PACKAGE> 
(Reading database ... 32393 files and directories currently installed.)
Removing <PACKAGE> (<VERSION) ...
Terminated
root@host:/data# echo $?
143
root@host:/data#

2番目に同じコマンドを実行したときに正しく機能しました。

root@host:/data# dpkg --purge <PACKAGE> 
(Reading database ... 32393 files and directories currently installed.)
Removing <PACKAGE> (<VERSION>) ...
dpkg: warning: while removing <PACKAGE>, unable to remove directory '/data': Device or resource busy - directory may be a mount point?
Purging configuration files for <PACKAGE> (<VERSION>) ...
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

私の質問は、dpkg --purge プロセスが最初に実行されたときに終了するのはなぜですか?何がそれを殺すのだろうか?

次のようなさまざまなログを確認してみました。

  • /var/log/dpkg.log
  • /var/log/apt/history.log
  • /var/log/apt/term.log
  • /var/lib/dpkg/info/<PACKAGE>.*.list、、、、、、).prerm​​​.postrm.preinst.postinst

しかし、何が起こっているのかについての有用な情報を提供することはありません。


メモ:Debian 8 32ビットシステムにインストールされているDebianパッケージ

詳細:

Debian パッケージは次の場所にファイルをインストールします。

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

管理者スクリプトは次のとおりです。

preinst

#!/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

#!/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

#!/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

#!/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 <PACKAGE>初めて実行すると、このようになります。half-configureddpkg手段によるThe package is unpacked and configuration has been started, but not yet completed for some reason.

root@host:/data# dpkg -s <PACKAGE>
[...]
Status: purge ok half-configured
[...]

また、スクリプトを手動で実行し、パッケージをインストールして手動で実行すると、削除が成功し、./prermファイルが正しく削除されます。./postrmdpkg -i <PACKAGE>

ベストアンサー1

メンテナンススクリプトでdpkgが実行する必要がある操作を再実装しようとしていますが、これらの呼び出しが行われるすべての方法を考慮していないようです。

たとえば、アップグレードプロセス中にprermとpostrmも呼び出されます。

私のアドバイスは、tarの奇妙なダンスを避け、.debから直接ファイルを提供し、.debに付属のすべてのファイルを手動で削除するのをやめることです。必要に応じてdpkgに開梱と取り外しを処理させます。

その後、Debianポリシーまたはさまざまなdeb-manページでsystemdが呼び出された時点のメンテナンススクリプトのフローチャートを確認する必要があります(現在はあまり詳細ではありません)。

おすすめ記事