yum update during reboot in RHEL 7

Latest response

Any ideas here:
server needs to perform 'yum update -y' during reboot so that new kernel is automatically installed and patched to latest version. I tried below in RHEL 7 but not working:
[Unit]
Description=Yum udpates
Before=systemd-reboot.service
DefaultDependencies=no
[Service]
ExecStart=/usr/bin/yum update -y
Type=forking
[Install]
WantedBy=reboot.target

when i change WantedBy=multi-user.target its working but that's when server is coming up which doesn't help.

expect to see: yum update needs to run when server is going down(not when server is coming up) so that upon reboot server boots with new kernel.

Responses

I'll probably get shot down in flames for this, but why not create a script file in /etc/rd.d/rc6.d called K01patch to issue your yum update -y

Redhat helped and provided solution: For redhat/centos: no need for perms change.

File: /etc/systemd/system/yum-update.service

Content:

#

[Unit] Description=yum-update After=local-fs.target remote-fs.target network.target network-online.target rsyslog.service

[Service] Type=oneshot RemainAfterExit=true ExecStart=/bin/true ExecStop=/bin/yum update -y

[Install] WantedBy=multi-user.target

#
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.