{"id":6482,"date":"2017-02-11T17:11:42","date_gmt":"2017-02-11T09:11:42","guid":{"rendered":"http:\/\/rmohan.com\/?p=6482"},"modified":"2017-02-11T17:11:42","modified_gmt":"2017-02-11T09:11:42","slug":"centos-yum-cron-automatic-reboot-after-kernel-update","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6482","title":{"rendered":"CentOS &#038; yum-cron: Automatic reboot after kernel update"},"content":{"rendered":"<div class=\"entry-content\">\n<p>If you\u2019re using yum-cron and want to automatically reboot your CentOS box whenever the kernel gets updated you can add this code to <code>\/etc\/cron.daily\/0yum.cron<\/code> right before <code>exit 0<\/code> at the end:<\/p>\n<p><code>entry=`cat \/boot\/grub\/grub.conf | grep '^default' | cut -d '=' -f2`<br \/>\nentry=`expr $entry + 1`<br \/>\nif [ \"`cat \/boot\/grub\/grub.conf | grep '^title' | tail <b>-n<\/b> +$entry | head -1 | sed -e 's\/.*(\\(.*\\)).*\/\\1\/'`\" != \"`uname -r`\" ]; then<br \/>\nsleep 10 ; reboot<br \/>\nfi<\/code><\/p>\n<p>This was taken from <a href=\"http:\/\/www-gat.univ-lille1.fr\/%7Ehafidi\/deploy_and_maintain_howto\/html\/maintain.html\" target=\"_blank\">here<\/a> with a tiny correction displayed in bold above.<\/p>\n<p>Depending on your version of CentOS you may want to adjust <code>\/etc\/anacrontab<\/code> or <code>\/etc\/crontab<\/code> to set the times when cron.daily and therefore yum-cron will be run to avoid reboots due to a kernel updates in the middle of the day.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\n<p>If you\u2019re using yum-cron and want to automatically reboot your CentOS box whenever the kernel gets updated you can add this code to \/etc\/cron.daily\/0yum.cron right before exit 0 at the end:<\/p>\n<p>entry=`cat \/boot\/grub\/grub.conf | grep &#8216;^default&#8217; | cut -d &#8216;=&#8217; -f2` entry=`expr $entry + 1` if [ &#8220;`cat \/boot\/grub\/grub.conf | grep &#8216;^title&#8217; | tail [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6482"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6482"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6482\/revisions"}],"predecessor-version":[{"id":6483,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6482\/revisions\/6483"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}