Automatically Install Updates Ubuntu


Updating your system at periodic time is a good practice. But some of us forgot to do so. In search of automatic updates I found Unattended Upgrade. You can modify the package as per your need.

To start, first you need to install Unattended-Upgrade

sudo apt-get install unattended-upgrades

Unattended-Upgrade calls /etc/cron.daily/apt
To set everything first create a file /etc/apt/apt.conf.d/10periodic and edit it with your favorite editor. For eg I am attaching my file below.

sudo /etc/apt/apt.conf.d/10periodic
APT::Periodic::Enable "1";
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "5";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::RandomSleep "1800";
APT::Periodic::Verbose "1";

Note: Details about what these values mean may be found in the header of the /etc/cron.daily/apt file.
When the apt job starts, it will sleep for a random period between 0 and APT::Periodic::RandomSleep seconds. The default value is “1800″ so that the script will stall for up to 30 minutes (1800 seconds) so that the mirror servers are not crushed by everyone running their updates all at the same time. Only set this to 0 if you use a local mirror and don’t mind the load spikes. Note that while the apt job is sleeping it will cause the execution of the rest of your cron.daily jobs to be delayed.

Now edit /etc/apt/apt.conf.d/50unattended-upgrades, it should look like below:

// Automatically upgrade packages from these (origin, archive) pairs
Unattended-Upgrade::Allowed-Origins {    
    // ${distro_id} and ${distro_codename} will be automatically expanded
    "${distro_id} stable";
    "${distro_id} ${distro_codename}-security";
    "${distro_id} ${distro_codename}-updates";
//  "${distro_id} ${distro_codename}-proposed-updates";
};
 
// List of packages to not update
Unattended-Upgrade::Package-Blacklist {
//  "vim";
//  "libc6";
//  "libc6-dev";
//  "libc6-i686";
};
 
// Send email to this address for problems or packages upgrades
// If empty or unset then no email is sent, make sure that you 
// have a working mail setup on your system. The package 'mailx'
// must be installed or anything that provides /usr/bin/mail.
Unattended-Upgrade::Mail "root@localhost";
 
// Do automatic removal of new unused dependencies after the upgrade
// (equivalent to apt-get autoremove)
Unattended-Upgrade::Remove-Unused-Dependencies "true";
 
// Automatically reboot *WITHOUT CONFIRMATION* if a 
// the file /var/run/reboot-required is found after the upgrade 
//Unattended-Upgrade::Automatic-Reboot "false";

Note : The double “//” serve as comments, so whatever follows “//” will not be evaluated

Now create STAMP file,

touch /var/lib/apt/periodic/update-stamp
touch /var/lib/apt/periodic/download-upgradeable-stamp
touch /var/lib/apt/periodic/upgrade-stamp
touch /var/lib/apt/periodic/autoclean-stamp

Now we will set cronjob to run the unattended-update

su
crontab -e
19 13 * * * /etc/cron.daily/apt > /home/vidyadhar/apt.log 2>&1

That’s it. The task will run at 1:19 PM every day.

Subscribe / Share

Article by Vidyadhar

My name is Vidyadhar Sarmalkar & I work as a consultant and have done RHCE & CCNA.
Vidyadhar tagged this post with: , , , , , , , , , , , Read 229 articles by

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Notify me of followup comments via e-mail. You can also subscribe without commenting.

rss twitter facbook

Categories

Archives

Buffer