{"id":646,"date":"2018-05-28T18:12:24","date_gmt":"2018-05-28T18:12:24","guid":{"rendered":"http:\/\/camilalui.com\/?p=646"},"modified":"2019-06-30T16:07:35","modified_gmt":"2019-06-30T16:07:35","slug":"646","status":"publish","type":"post","link":"https:\/\/camilalui.com\/?p=646","title":{"rendered":"Ubuntu with \/var\/lib\/dpkg locked"},"content":{"rendered":"<p><strong>Error:<\/strong><br \/>\n&#8220;Could not get lock \/var\/lib\/dpkg\/lock &#8211; open (11: Resource temporarily unavailable)&#8221;<\/p>\n<p>As soon as you have your Ubuntu 16.04 machine up provisioned by either Ansible or Vagrant, it starts a process for unattended-updates that locks the dpkg repository and any script that needs to send instructions for apt app, will fail.<\/p>\n<p>This appears to be caused by a combination of an unattended-upgraded package policy set by the Debian\/Ubuntu, and a change in how unattended upgrades are handled now.<\/p>\n<p>In past versions of Ubuntu, unattended package upgrades were handled by creating a cron job in \/etc\/cron.daily responsible for running apt. With 16.04 version and the shift to systemd, unattended upgrades are handled by a systemd unit. The new systemd unit has OnCalendar set to 6am and 6pm, along with Persistent set to true. The result is that a full apt-get update &amp;&amp; apt-get upgrade will run the first time the system boots, in order to &#8220;catch-up&#8221; with missed runs.<\/p>\n<p>The idea that packages will be upgraded automatically twice a day, so what you can do is to disable the automatic apt upgrades at all.<br \/>\n<strong><br \/>\nHow to disable apt automatic updates:<br \/>\n<\/strong><\/p>\n<p>You have to edit this file:<\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"shell\" name=\"mshighlighter\" >\r\n\/etc\/apt\/apt.conf.d\/10periodic<\/textarea><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Change the line:<\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"shell\" name=\"mshighlighter\" >\r\nAPT::Periodic::Update-Package-Lists \"1\";<\/textarea><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>To:<\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"shell\" name=\"mshighlighter\" >\r\nAPT::Periodic::Update-Package-Lists \"0\";<\/textarea><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Edit this file:<\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"shell\" name=\"mshighlighter\" >\r\n\/etc\/apt\/apt.conf.d\/20auto-upgrades<\/textarea><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Change these lines:<\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"shell\" name=\"mshighlighter\" >\r\nAPT::Periodic::Update-Package-Lists \"1\";\r\nAPT::Periodic::Unattended-Upgrade \"1\";<\/textarea><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>To:<\/p>\n<div class=\"my-syntax-highlighter\">\n<pre><textarea id=\"mshighlighter\" class=\"mshighlighter\" language=\"shell\" name=\"mshighlighter\" >\r\nAPT::Periodic::Update-Package-Lists \"0\"\r\nAPT::Periodic::Unattended-Upgrade \"0\";<\/textarea><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Just remember to set the automatic updates ON again after your provision in case this machine is a server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Error: &#8220;Could not get lock \/var\/lib\/dpkg\/lock &#8211; open (11: Resource temporarily unavailable)&#8221; As soon as you have your Ubuntu 16.04 machine up provisioned by either Ansible or Vagrant, it starts a process for unattended-updates that locks the dpkg repository and any script that needs to send instructions for apt app, will fail. This appears to<a class=\"more-link\" href=\"https:\/\/camilalui.com\/?p=646\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_price":"","_stock":"","_tribe_ticket_header":"","_tribe_default_ticket_provider":"","_tribe_ticket_capacity":"0","_ticket_start_date":"","_ticket_end_date":"","_tribe_ticket_show_description":"","_tribe_ticket_show_not_going":false,"_tribe_ticket_use_global_stock":"","_tribe_ticket_global_stock_level":"","_global_stock_mode":"","_global_stock_cap":"","_tribe_rsvp_for_event":"","_tribe_ticket_going_count":"","_tribe_ticket_not_going_count":"","_tribe_tickets_list":"[]","_tribe_ticket_has_attendee_info_fields":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_tec_slr_enabled":"","_tec_slr_layout":""},"categories":[27],"tags":[],"class_list":["post-646","post","type-post","status-publish","format-standard","hentry","category-ubuntu"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s9toiJ-646","jetpack_likes_enabled":true,"jetpack-related-posts":[],"ticketed":false,"_links":{"self":[{"href":"https:\/\/camilalui.com\/index.php?rest_route=\/wp\/v2\/posts\/646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/camilalui.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/camilalui.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/camilalui.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/camilalui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=646"}],"version-history":[{"count":15,"href":"https:\/\/camilalui.com\/index.php?rest_route=\/wp\/v2\/posts\/646\/revisions"}],"predecessor-version":[{"id":797,"href":"https:\/\/camilalui.com\/index.php?rest_route=\/wp\/v2\/posts\/646\/revisions\/797"}],"wp:attachment":[{"href":"https:\/\/camilalui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/camilalui.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/camilalui.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}