Skip to content

Commit df84f6a

Browse files
committed
Avoid dpkg lock during Packer provisioner shell execution
Instead of disabling the Update Package List and Unattended Upgrade in the apt configuration, wait until dpkg lock is released and temporarily stop the apt-daily services for the Packer duration. ``` $apt-config shell StateDir Dir::State/d StateDir='/var/lib/apt/' ``` ``` $echo $(apt-config shell StateDir Dir::State/d | sed -r "s/.*'(.*)\/?'$/\1/")/daily_lock /var/lib/apt/daily_lock ``` Signed-off-by: Luca Carrogu <[email protected]>
1 parent edc39c9 commit df84f6a

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

amis/packer_ubuntu1604.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,15 @@
153153
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done"
154154
]
155155
},
156+
{
157+
"type": "shell",
158+
"inline": [
159+
"sudo flock $(apt-config shell StateDir Dir::State/d | sed -r \"s/.*'(.*)\\/?'$/\\1/\")/daily_lock systemctl stop apt-daily.timer apt-daily.service"
160+
]
161+
},
156162
{
157163
"type" : "shell",
158164
"inline" : [
159-
"sudo sed -i 's/APT::Periodic::Update-Package-Lists \"1\"/APT::Periodic::Update-Package-Lists \"0\"/' /etc/apt/apt.conf.d/20auto-upgrades",
160-
"sudo sed -i 's/APT::Periodic::Update-Package-Lists \"1\"/APT::Periodic::Update-Package-Lists \"0\"/' /etc/apt/apt.conf.d/10periodic",
161-
"sudo sed -i 's/APT::Periodic::Unattended-Upgrade \"1\"/APT::Periodic::Unattended-Upgrade \"0\"/' /etc/apt/apt.conf.d/20auto-upgrades",
162165
"sudo apt-cache search build-essential",
163166
"sudo apt-get clean",
164167
"sudo apt-get update"

amis/packer_ubuntu1804.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@
154154
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done"
155155
]
156156
},
157+
{
158+
"type": "shell",
159+
"inline": [
160+
"sudo flock $(apt-config shell StateDir Dir::State/d | sed -r \"s/.*'(.*)\\/?'$/\\1/\")/daily_lock systemctl stop apt-daily.timer apt-daily.service"
161+
]
162+
},
157163
{
158164
"type" : "shell",
159165
"inline" : [
160-
"sudo sed -i 's/APT::Periodic::Update-Package-Lists \"1\"/APT::Periodic::Update-Package-Lists \"0\"/' /etc/apt/apt.conf.d/20auto-upgrades",
161-
"sudo sed -i 's/APT::Periodic::Update-Package-Lists \"1\"/APT::Periodic::Update-Package-Lists \"0\"/' /etc/apt/apt.conf.d/10periodic",
162-
"sudo sed -i 's/APT::Periodic::Unattended-Upgrade \"1\"/APT::Periodic::Unattended-Upgrade \"0\"/' /etc/apt/apt.conf.d/20auto-upgrades",
163166
"sudo apt-cache search build-essential",
164167
"sudo apt-get clean",
165168
"sudo apt-get update"

0 commit comments

Comments
 (0)