# Server's reboot action

**URL:** <https://discourse.chef.io/t/servers-reboot-action/3068>\
**Category:** Chef Infra (archive)\
**Created:** [August 30, 2012, 9:31am UTC](https://discourse.chef.io/t/servers-reboot-action/3068 "2012-08-30T09:31:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vlad\_Berezovski](https://avatars.discourse-cdn.com/v4/letter/v/e5b9ba/32.png) [@Vlad\_Berezovski](https://discourse.chef.io/u/Vlad_Berezovski)\
**Post date:** [August 30, 2012, 9:31am UTC](https://discourse.chef.io/t/servers-reboot-action/3068/1 "2012-08-30T09:31:20Z")

</div>

Just started to work with recipies . How to define server’s reboot ?

---

<div class="post-metadata">

**Author:** ![Sean\_Horn](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/sean_horn/32/445_2.png) [@Sean\_Horn](https://discourse.chef.io/u/Sean_Horn)\
**Post date:** [August 30, 2012, 3:10pm UTC](https://discourse.chef.io/t/servers-reboot-action/3068/2 "2012-08-30T15:10:24Z")

</div>

Vlad,

However you would do a reboot on the command line, you could do the same in  
an "execute" resource.

On Thu, Aug 30, 2012 at 5:31 AM, [vlad.berezovski@gmail.com](mailto:vlad.berezovski@gmail.com) wrote:

> Just started to work with recipies . How to define server's reboot ?

---

<div class="post-metadata">

**Author:** ![Bryan\_McLellan](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/bryan_mclellan/32/81_2.png) [@Bryan\_McLellan](https://discourse.chef.io/u/Bryan_McLellan)\
**Post date:** [August 30, 2012, 7:03pm UTC](https://discourse.chef.io/t/servers-reboot-action/3068/3 "2012-08-30T19:03:15Z")

</div>

On Thu, Aug 30, 2012 at 5:31 AM, [vlad.berezovski@gmail.com](mailto:vlad.berezovski@gmail.com) wrote:

> Just started to work with recipies . How to define server's reboot ?

This is a terrible abuse of resources due to the lack of being able to  
trigger a notification as a first class object, but this works for  
triggering a reboot toward the end of the run. There is not a way to  
control the order of the delayed notifications though, so if you have  
notifications that are important this might run before them. Usually  
delayed notifications are for services though, and since you're  
rebooting anyway, that shouldn't be a problem.

execute "reboot" do  
command "reboot"  
action :nothing  
end

ruby\_block "trigger delayed reboot" do  
block { true }  
notifies :run, "execute[reboot]", :delayed  
end

---

<div class="post-metadata">

**Author:** ![John\_Dewey](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_dewey/32/457_2.png) [@John\_Dewey](https://discourse.chef.io/u/John_Dewey)\
**Post date:** [August 30, 2012, 8:05pm UTC](https://discourse.chef.io/t/servers-reboot-action/3068/4 "2012-08-30T20:05:37Z")

</div>

I believe this approach would prevent the chef-client from completing. Thus preventing the node's status from being saved back to the server. If you were to change it to a shutdown with a delay that would probably work better.

It might be better to use a handler to deal with reboots. I have a cookbook I was working on that attempted this. A cookbook which made a change requiring a reboot would set node.run\_state['reboot'] to true. The handler would then deal with rebooting the system if it was set && met some additional criterial. I am using this to pivot hypervisors interfaces to bonded, before assigning the systems their OpenStack roles.

[https://github.com/retr0h/reboot-handler](https://github.com/retr0h/reboot-handler)

On Thursday, August 30, 2012 at 12:03 PM, Bryan McLellan wrote:

> On Thu, Aug 30, 2012 at 5:31 AM, \<[vlad.berezovski@gmail.com](mailto:vlad.berezovski@gmail.com) ([mailto:vlad.berezovski@gmail.com](mailto:vlad.berezovski@gmail.com))\> wrote:
> 
> > Just started to work with recipies . How to define server's reboot ?
> 
> This is a terrible abuse of resources due to the lack of being able to  
> trigger a notification as a first class object, but this works for  
> triggering a reboot toward the end of the run. There is not a way to  
> control the order of the delayed notifications though, so if you have  
> notifications that are important this might run before them. Usually  
> delayed notifications are for services though, and since you're  
> rebooting anyway, that shouldn't be a problem.
> 
> execute "reboot" do  
> command "reboot"  
> action :nothing  
> end
> 
> ruby\_block "trigger delayed reboot" do  
> block { true }  
> notifies :run, "execute[reboot]", :delayed  
> end
