# Chef Reboot, how to reboot only when required

**URL:** <https://discourse.chef.io/t/chef-reboot-how-to-reboot-only-when-required/11850>\
**Category:** Chef Infra (archive)\
**Created:** [November 1, 2017, 1:55pm UTC](https://discourse.chef.io/t/chef-reboot-how-to-reboot-only-when-required/11850 "2017-11-01T13:55:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![seinarsson](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@seinarsson](https://discourse.chef.io/u/seinarsson)\
**Post date:** [November 1, 2017, 1:55pm UTC](https://discourse.chef.io/t/chef-reboot-how-to-reboot-only-when-required/11850/1 "2017-11-01T13:55:21Z")

</div>

How do I detect if a reboot is required? One of my recipes is failing because a previous recipe puts the machine in a state that requires a reboot.

I’ve looked through this…  
[https://docs.chef.io/resource\_reboot.html](https://docs.chef.io/resource_reboot.html)

And it shows how to reboot immediately, but won’t that mean the machine reboots everytime chef runs? How do you only reboot if it’s required?

---

<div class="post-metadata">

**Author:** ![simark](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/simark/32/2099_2.png) [@simark](https://discourse.chef.io/u/simark)\
**Post date:** [November 1, 2017, 2:50pm UTC](https://discourse.chef.io/t/chef-reboot-how-to-reboot-only-when-required/11850/2 "2017-11-01T14:50:29Z")

</div>

You should define your reboot resource with an `action :nothing` and trigger it from another resource with the notify block.

You can see examples in the `reboot` resource page  
[https://docs.chef.io/resource\_reboot.html#examples](https://docs.chef.io/resource_reboot.html#examples)

---

<div class="post-metadata">

**Author:** ![Todd\_Pigram](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/todd_pigram/32/138_2.png) [@Todd\_Pigram](https://discourse.chef.io/u/Todd_Pigram)\
**Post date:** [November 1, 2017, 6:01pm UTC](https://discourse.chef.io/t/chef-reboot-how-to-reboot-only-when-required/11850/3 "2017-11-01T18:01:51Z")

</div>

On the windows side, I do the following

reboot ‘Only if needed’ do  
action :request\_reboot  
reason 'Need to reboot when the run completes successfully.'  
delay\_mins 2  
only\_if { reboot\_pending? }  
end
