![Ubuntu 클라우드 가상 머신 이미지에서 "apt-daily.service"를 비활성화하는 방법은 무엇입니까?](https://linux55.com/image/96194/Ubuntu%20%ED%81%B4%EB%9D%BC%EC%9A%B0%EB%93%9C%20%EA%B0%80%EC%83%81%20%EB%A8%B8%EC%8B%A0%20%EC%9D%B4%EB%AF%B8%EC%A7%80%EC%97%90%EC%84%9C%20%22apt-daily.service%22%EB%A5%BC%20%EB%B9%84%ED%99%9C%EC%84%B1%ED%99%94%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
Ubuntu 16.04 서버 VM 이미지는 약 12시간마다 "apt-daily.service"를 시작하는 것으로 보입니다. 이 서비스는 사용 가능한 패키지 목록 새로 고침, 필요에 따라 무인 업그레이드 수행 등과 같은 다양한 APT 관련 작업을 수행합니다.
이 서비스는 가상 머신 "스냅샷"에서 부팅할 때 트리거됩니다.곧, (아마도) systemd는 타이머가 오래 전에 꺼져 있어야 한다는 것을 빨리 깨달았기 때문입니다.
그러나 실행 중인 APT는 을 apt
(를) 보유하므로 다른 프로세스가 실행되지 않습니다 /var/lib/dpkg
.
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?
Ansible이 시스템 설정을 완료할 때까지(일반적으로 패키지 설치가 포함됨) 이 자동 APT 작업을 비활성화해야 합니다.https://github.com/gc3-uzh-ch/elasticluster/issues/304자세한 내용과 배경을 알아보세요.
"사용자 데이터" 스크립트를 통해 "무인 업그레이드" 기능을 비활성화하기 위해 다양한 옵션을 시도했지만 cloud-init
지금까지 모두 실패했습니다.
1. 시스템 작업 비활성화
systemd 작업은 apt-daily.service
에 의해 트리거됩니다 apt-daily.timer
. 다음 명령 중 하나 또는 둘 다를 비활성화하기 위해 다양한 조합을 사용해 보았지만 apt-daily.service
VM이 SSH 연결을 수락할 준비가 되자마자 시작됩니다.
#!/bin/bash
systemctl stop apt-daily.timer
systemctl disable apt-daily.timer
systemctl mask apt-daily.service
systemctl daemon-reload
2. 구성 옵션 비활성화APT::Periodic::Enable
스크립트는 /usr/lib/apt/apt.systemd.daily
일부 APT 구성 변수를 읽습니다. 이 설정은 APT::Periodic::Enable
기능을 완전히 비활성화합니다(331-337행). 다음 스크립트를 사용하여 비활성화해 보았습니다.
#!/bin/bash
# cannot use /etc/apt/apt.conf.d/10periodic as suggested in
# /usr/lib/apt/apt.systemd.daily, as Ubuntu distributes the
# unattended upgrades stuff with priority 20 and 50 ...
# so override everything with a 99xxx file
cat > /etc/apt/apt.conf.d/99elasticluster <<__EOF
APT::Periodic::Enable "0";
// undo what's in 20auto-upgrade
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Unattended-Upgrade "0";
__EOF
그러나 명령줄(아래 참조)에서 APT::Periodic::Enable
값을 가져왔음 에도 불구하고 프로그램은 계속 실행됩니다...0
unattended-upgrades
ubuntu@test:~$ apt-config shell AutoAptEnable APT::Periodic::Enable
AutoAptEnable='0'
3. /usr/lib/apt/apt.systemd.daily
완전삭제
다음 cloud-init
스크립트는 무인 업그레이드 스크립트를 완전히 제거합니다.
#!/bin/bash
mv /usr/lib/apt/apt.systemd.daily /usr/lib/apt/apt.systemd.daily.DISABLED
그럼에도 불구하고 작업은 여전히 실행 중이며 프로세스 테이블에서 볼 수 있습니다! 명령줄에서 검색하면 파일이 존재하지 않습니다.:
ubuntu@test:~$ ls /usr/lib/apt/apt.systemd.daily
ls: cannot access '/usr/lib/apt/apt.systemd.daily': No such file or directory
cloud-init
SSH 명령줄과 함께 스크립트와 루트 시스템 프로세스가 별도의 파일 시스템과 프로세스 공간에서 실행되는 것처럼 보입니다 .
질문
나는 분명한 것을 놓치고 있습니까? 아니면 내가 모르는 네임스페이스 마법이 진행되고 있는 걸까요?
가장 중요한 것은: 스크립트를 apt-daily.service
통해 어떻게 cloud-init
비활성화 할 수 있습니까?
답변1
예, 분명히 뭔가 빠졌습니다.
Systemd는 서비스의 동시 시작에 관한 것이므로 cloud-init
스크립트 실행동시에트리거 됩니다 apt-daily.service
. cloud-init
사용자가 지정한 페이로드가 실행 되면
apt-get update
이미 실행 중입니다. 따라서 시도 2와 3은 네임스페이스 마법 때문이 아니라 시스템에 너무 늦게 도입되어 apt.systemd.daily
변경 사항을 수용할 수 없었기 때문에 실패했습니다.
이는 또한 기본적으로 방법이 없음을 의미합니다.방지
apt.systemd.daily
실행을 방지합니다. 시작된 후에만 종료하세요.
이 "userdata" 스크립트는 다음 경로를 사용합니다.
#!/bin/bash
systemctl stop apt-daily.service
systemctl kill --kill-who=all apt-daily.service
# wait until `apt-get updated` has been killed
while ! (systemctl list-units --all apt-daily.service | egrep -q '(dead|failed)')
do
sleep 1;
done
# now proceed with own APT tasks
apt install -y python
SSH 로그인이 가능하지만 작동하지 않는 시간이 여전히 있지만 apt-get
Ubuntu 16.04 클라우드 이미지에서 작동하는 다른 솔루션은 상상할 수 없습니다.
답변2
참고: 불행하게도 아래 솔루션의 일부입니다.Ubuntu 16.04 시스템에는 적용되지 않습니다.(예: 질문자의) 제안된 systemd-run
전화는 다음에만 적용되므로우분투 18.04 이상(보다자세히 알아보려면 댓글을 달아주세요). 어떤 Ubuntu 버전을 사용하든 이 질문은 여전히 인기가 있기 때문에 여기에 답변을 남길 것입니다.
Ubuntu 18.04(이상)에서는 시작 시 적절한 업데이트/업그레이드에 최대 2개의 서비스가 포함될 수 있습니다. 첫 번째는 apt-daily.service
패키지 목록을 새로 고칩니다. 그러나 apt-daily-upgrade.service
보안에 중요한 두 번째 패키지가 실제로 설치되어 있을 수도 있습니다 . 하나"명령이 반환되기 전에 무인 업그레이드 종료 및 비활성화/제거"에 응답하십시오.이 질문은 이 두 작업이 완료될 때까지 기다리는 방법에 대한 좋은 예를 제공합니다(편의를 위해 여기에 복사됨).
systemd-run --property="After=apt-daily.service apt-daily-upgrade.service" --wait /bin/true
(이것은 루트로 실행되어야 합니다.) 향후 출시 시 이러한 서비스를 비활성화하려면 다음 두 서비스를 차단해야 합니다.
systemctl mask apt-daily.service apt-daily-upgrade.service
또는 systemctl disable
서비스와 관련 타이머(예: apt-daily.timer
및 apt-daily-upgrade.timer
)를 모두 사용할 수 있습니다.
이 답변의 차단/비활성화 기술은 향후 실행 시 업데이트/업그레이드만 차단합니다. 현재 부팅 시 이미 실행 중인 경우에는 차단하지 않습니다.
답변3
"bootcmd" cloud-init 모듈을 통해 이 기능을 비활성화할 수 있습니다. 네트워크가 시작되기 전에 실행되며, 이는 적절한 업데이트가 실행되기 전에 필요합니다.
#cloud-config
bootcmd:
- echo 'APT::Periodic::Enable "0";' > /etc/apt/apt.conf.d/10cloudinit-disable
- apt-get -y purge update-notifier-common ubuntu-release-upgrader-core landscape-common unattended-upgrades
- echo "Removed APT and Ubuntu 18.04 garbage early" | systemd-cat
인스턴스에 SSH로 연결한 후에는 적절한 소스/목록을 이동하면서 cloud-init의 마지막 단계가 완료될 때까지 기다려야 합니다.
# Wait for cloud-init to finish moving apt sources.list around...
# a good source of random failures
# Note this is NOT a replacement for also disabling apt updates via bootcmd
while [ ! -f /var/lib/cloud/instance/boot-finished ]; do
echo 'Waiting for cloud-init to finish...'
sleep 3
done
bootcmd를 실행하는 데 걸린 시간을 확인하는 것도 도움이 됩니다.
# Show microseconds in systemd journal
journalctl -r -o short-precise
다음과 같이 작동하는지 확인할 수 있습니다.
apt-config dump | grep Periodic
# Verify nothing was updated until we run apt update ourselves.
cd /var/lib/apt/lists
sudo du -sh . # small size
ls -ltr # old timestamps
답변4
이 장치를 은폐하는 것이 더 쉽지 않을까요?
systemctl mask apt-daily.service
?