大网数据广告活动
服务器运维问答

Can I kill apt.system.daily to fix the apt install command?

· 52CE 我爱测

When I try to install anything (Ubuntu 16.04) with apt or apt-get I get this: E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable) E: Unable to acquire the dpkg frontend lock (/var/lib/d…

问题原文

原帖链接 · CzipO2 · CC BY-SA 4.0

When I try to install anything (Ubuntu 16.04) with apt or apt-get I get this:

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

This is the output of ps aux | grep apt:

root     23906  0.0  0.0   4504   784 ?        Ss   Feb20   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily install
root     23912  0.0  0.0   4504  1640 ?        S    Feb20   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install

But these are the sub processes:

root     23906  0.0  0.0   4504   784 ?        Ss   Feb20   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily install
root     23912  0.0  0.0   4504  1640 ?        S    Feb20   0:00  \_ /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held install
root     23943  0.1  3.7 140052 77424 ?        S    Feb20  56:54      \_ /usr/bin/python3 /usr/bin/unattended-upgrade
root     23948  0.0  0.0      0     0 ?        Z    Feb20   0:00          \_ [dpkg-deb] <defunct>
root     23965  0.0  2.9 140632 59508 ?        S    Feb20  31:44          \_ /usr/bin/python3 /usr/bin/unattended-upgrade
root     24051  0.0  0.2  19196  4632 pts/0    Ss+  Feb20   0:00              \_ /usr/bin/dpkg --status-fd 10 --configure redis-server:amd64 linux-modules-4.4.0-1102-aws:amd64 linux-image-4.4.0-1102-aws:amd64 linux-image-aws:amd64 linux-a
root     24052  0.0  0.0   4504  1660 pts/0    S+   Feb20   0:00                  \_ /bin/sh /var/lib/dpkg/info/redis-server.postinst configure
root     24094  0.0  0.0   4504  1696 pts/0    S+   Feb20   0:00                      \_ /bin/sh /usr/sbin/invoke-rc.d redis-server start
root     24138  0.0  0.0  24888  1340 pts/0    S+   Feb20   0:11                          \_ systemctl start redis-server.service

I believe that the PIDs from ps aux | grep apt are holding my apt install command but I don't want to kill the redis-server PID in the subprocesses and all the other PIDs eventhough systemctl status says that both redis and redis server state is deactivating (stop-post). And last time someone tried to install anything was redis-server

社区高分解答

原帖链接 · cr3a7ure · CC BY-SA 4.0

Those are unattended upgrades, which acquire a different lock than the usual apt-get.

The simple way to install after the unattended upgrades pass is by waiting its lock to finish with flock. flock will wait until the lock is released and then it will execute sequentially update, upgrade and install.

 flock /var/lib/apt/daily_lock \
  apt-get -y update \
  && apt-get -y upgrade \
  && apt-get -y install \
    zip \
    unzip

References:

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-03-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。