Skip to content

Instantly share code, notes, and snippets.

@jornane
Last active March 14, 2023 06:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jornane/c29a761893293c6c42ce6901d46442f7 to your computer and use it in GitHub Desktop.
Save jornane/c29a761893293c6c42ce6901d46442f7 to your computer and use it in GitHub Desktop.
Enable automatic updating on CentOS 7
yum install -y yum-cron yum-utils
sed -i -e '/apply_updates/ s/no/yes/' /etc/yum/yum-cron.conf
tee /etc/cron.daily/0autoreboot.cron <<EOF
#!/bin/sh
needs-restarting -r >/dev/null || { reboot; exit 0; }
needs-restarting -s | grep -q auditd.service && { reboot; exit 0; }
needs-restarting -s | xargs --no-run-if-empty -n1 systemctl restart
EOF
chmod +x /etc/cron.daily/0autoreboot.cron
# yum-cron is scheduled to start at boot, but not running
# We can start it now
systemctl start yum-cron
# Or we can upgrade everything now, and reboot if needed
yum clean all && yum upgrade && /etc/cron.daily/0autoreboot.cron && systemctl start yum-cron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment