Regarding Reboot Handler

Hi All,

I have an use case where I need to reboot the machine if there is any new
kernel update/install.

I am trying to write an LWRP for reboot handler that can be used in other
recipe’s also.

I will be calling linux_reboot once there is an kernel update.

added this code in recipe for reboot:;

  linux_reboot 'kernel updated' do
     action :reboot
       end

resource/reboot.rb

    actions :reboot
      default_action :reboot


    attribute :happened, kind_of: String

    attr_accessor :exists

provider/reboot.rb

def whyrun_supported?
  true
end


action :reboot do

Chef::Log.info "=== Cookbook: #{cookbook_name}"
  Chef::Log.info "=== Resource Name: #{@new_resource.name}"

 if @current_resource.happened
  Chef::Log.info 'Reboot happened'
  else
    converge_by("Reboot system") do
      reboot
    end
  end

end

def load_current_resource
@current_resource = Chef::Resource::linuxReboot.new(@new_resource.name)
@current_resource.happened = false

begin

search for a file and set the flag…

end

Chef::Log.debug “Reboot debug message”

@current_resource
end

def reboot
Chef::Log.info 'Reboot The Machine’
end


what is the best way to indicate a reboot happened. shall I look for a file
indicating a reboot or something else??
I am thinking to search for a file and if the reboot happened then set
happened=true and return. will this work and is the right approach??

Thanks & Regards,
Sachin Kumar

Linux has uptime command I think it`s the best way to indicate reboot
happened.
I hope, it will help.

2015-01-12 11:17 GMT+02:00 Sachin Gupta guptasachin1112mrt@gmail.com:

Hi All,

I have an use case where I need to reboot the machine if there is any new
kernel update/install.

I am trying to write an LWRP for reboot handler that can be used in other
recipe's also.

I will be calling linux_reboot once there is an kernel update.

added this code in recipe for reboot:;

  linux_reboot 'kernel updated' do
     action :reboot
       end

resource/reboot.rb

    actions :reboot
      default_action :reboot


    attribute :happened, kind_of: String

    attr_accessor :exists

provider/reboot.rb

def whyrun_supported?
  true
end


action :reboot do

Chef::Log.info "=== Cookbook: #{cookbook_name}"
  Chef::Log.info "=== Resource Name: #{@new_resource.name}"

 if @current_resource.happened
  Chef::Log.info 'Reboot happened'
  else
    converge_by("Reboot system") do
      reboot
    end
  end

end

def load_current_resource
@current_resource = Chef::Resource::linuxReboot.new(@new_resource.name)
@current_resource.happened = false

begin

search for a file and set the flag..

end

Chef::Log.debug "Reboot debug message"

@current_resource
end

def reboot
Chef::Log.info 'Reboot The Machine'
end


what is the best way to indicate a reboot happened. shall I look for a
file indicating a reboot or something else??
I am thinking to search for a file and if the reboot happened then set
happened=true and return. will this work and is the right approach??

Thanks & Regards,
Sachin Kumar

--


PRIVILEGED AND CONFIDENTIAL COMMUNICATION
This e-mail transmission, and any documents, files or previous e-mail
messages
attached to it, may contain confidential information that is legally
privileged.

If you are not the intended recipient or a person responsible for
delivering it
to the intended recipient, you are hereby notified that any disclosure,
copying,
distribution or use of any of the information contained in or attached to
this
transmission is strictly prohibited.

If you have received this transmission in error, please: (1) immediately
notify
me by reply e-mail, or by collect telephone call; and (2) destroy the
original
transmission and its attachments without reading or saving in any manner.

There is an @reboot cron and similar in system timers - I think they would
be beneficial for this, checking for a shot uptime is likely to be
inconsistent.

Kimball

On 12 January 2015 at 10:13, Sergii Bieliaievskyi <s.bieliaievskyi@sethq.com

wrote:

Linux has uptime command I think it`s the best way to indicate reboot
happened.
I hope, it will help.

2015-01-12 11:17 GMT+02:00 Sachin Gupta guptasachin1112mrt@gmail.com:

Hi All,

I have an use case where I need to reboot the machine if there is any new
kernel update/install.

I am trying to write an LWRP for reboot handler that can be used in other
recipe's also.

I will be calling linux_reboot once there is an kernel update.

added this code in recipe for reboot:;

  linux_reboot 'kernel updated' do
     action :reboot
       end

resource/reboot.rb

    actions :reboot
      default_action :reboot


    attribute :happened, kind_of: String

    attr_accessor :exists

provider/reboot.rb

def whyrun_supported?
  true
end


action :reboot do

Chef::Log.info "=== Cookbook: #{cookbook_name}"
  Chef::Log.info "=== Resource Name: #{@new_resource.name}"

 if @current_resource.happened
  Chef::Log.info 'Reboot happened'
  else
    converge_by("Reboot system") do
      reboot
    end
  end

end

def load_current_resource
@current_resource = Chef::Resource::linuxReboot.new(@new_resource.name)
@current_resource.happened = false

begin

search for a file and set the flag..

end

Chef::Log.debug "Reboot debug message"

@current_resource
end

def reboot
Chef::Log.info 'Reboot The Machine'
end


what is the best way to indicate a reboot happened. shall I look for a
file indicating a reboot or something else??
I am thinking to search for a file and if the reboot happened then set
happened=true and return. will this work and is the right approach??

Thanks & Regards,
Sachin Kumar


PRIVILEGED AND CONFIDENTIAL COMMUNICATION
This e-mail transmission, and any documents, files or previous e-mail
messages
attached to it, may contain confidential information that is legally
privileged.

If you are not the intended recipient or a person responsible for
delivering it
to the intended recipient, you are hereby notified that any disclosure,
copying,
distribution or use of any of the information contained in or attached to
this
transmission is strictly prohibited.

If you have received this transmission in error, please: (1) immediately
notify
me by reply e-mail, or by collect telephone call; and (2) destroy the
original
transmission and its attachments without reading or saving in any manner.

There are a lot of possibilities including cron. Here are more:

  1. last reboot
  2. who -b

Topic starter has many options now.

2015-01-12 12:19 GMT+02:00 Kimball Johnson kimball@bowerham.net:

There is an @reboot cron and similar in system timers - I think they would
be beneficial for this, checking for a shot uptime is likely to be
inconsistent.

Kimball

On 12 January 2015 at 10:13, Sergii Bieliaievskyi <
s.bieliaievskyi@sethq.com> wrote:

Linux has uptime command I think it`s the best way to indicate reboot
happened.
I hope, it will help.

2015-01-12 11:17 GMT+02:00 Sachin Gupta guptasachin1112mrt@gmail.com:

Hi All,

I have an use case where I need to reboot the machine if there is any
new kernel update/install.

I am trying to write an LWRP for reboot handler that can be used in
other recipe's also.

I will be calling linux_reboot once there is an kernel update.

added this code in recipe for reboot:;

  linux_reboot 'kernel updated' do
     action :reboot
       end

resource/reboot.rb

    actions :reboot
      default_action :reboot


    attribute :happened, kind_of: String

    attr_accessor :exists

provider/reboot.rb

def whyrun_supported?
  true
end


action :reboot do

Chef::Log.info "=== Cookbook: #{cookbook_name}"
  Chef::Log.info "=== Resource Name: #{@new_resource.name}"

 if @current_resource.happened
  Chef::Log.info 'Reboot happened'
  else
    converge_by("Reboot system") do
      reboot
    end
  end

end

def load_current_resource
@current_resource = Chef::Resource::linuxReboot.new(@new_resource.name
)
@current_resource.happened = false

begin

search for a file and set the flag..

end

Chef::Log.debug "Reboot debug message"

@current_resource
end

def reboot
Chef::Log.info 'Reboot The Machine'
end


what is the best way to indicate a reboot happened. shall I look for a
file indicating a reboot or something else??
I am thinking to search for a file and if the reboot happened then set
happened=true and return. will this work and is the right approach??

Thanks & Regards,
Sachin Kumar


PRIVILEGED AND CONFIDENTIAL COMMUNICATION
This e-mail transmission, and any documents, files or previous e-mail
messages
attached to it, may contain confidential information that is legally
privileged.

If you are not the intended recipient or a person responsible for
delivering it
to the intended recipient, you are hereby notified that any disclosure,
copying,
distribution or use of any of the information contained in or attached to
this
transmission is strictly prohibited.

If you have received this transmission in error, please: (1) immediately
notify
me by reply e-mail, or by collect telephone call; and (2) destroy the
original
transmission and its attachments without reading or saving in any manner.

--


PRIVILEGED AND CONFIDENTIAL COMMUNICATION
This e-mail transmission, and any documents, files or previous e-mail
messages
attached to it, may contain confidential information that is legally
privileged.

If you are not the intended recipient or a person responsible for
delivering it
to the intended recipient, you are hereby notified that any disclosure,
copying,
distribution or use of any of the information contained in or attached to
this
transmission is strictly prohibited.

If you have received this transmission in error, please: (1) immediately
notify
me by reply e-mail, or by collect telephone call; and (2) destroy the
original
transmission and its attachments without reading or saving in any manner.

Hi Sergii/Kimball,

I am able to write reboot handler and this is working fine as expected but
still needs to know whether this is the right approach. this is my first
LWRP..

linux_reboot 'kernel updated' do
action :reboot
end

provider/reboot.rb

action :reboot do

Chef::Log.info "=== Cookbook: #{cookbook_name}"
Chef::Log.info '=== Resource: Reboot / Action: reboot'
Chef::Log.info "=== Resource Name: #{@new_resource.name}"

    converge_by("rebooting the system immediately") do
      Chef::Log.warn "Rebooting system immediately, requested by '#{@

new_resource.name}'"
reboot
end

def load_current_resource
@current_resource = Chef::Resource::linuxReboot.new(@new_resource.name)
@current_resource
end

def reboot
Chef::Log.info 'Reboot*************************************'
Mixlib::ShellOut.new(node[:linux][:command]).run_command
end

command is defined in attribute file as

default[:linux][:command] = 'shutdown -r +1&'

Thanks & Regards,
Sachin Kumar

On Mon, Jan 12, 2015 at 3:58 PM, Sergii Bieliaievskyi <
s.bieliaievskyi@sethq.com> wrote:

There are a lot of possibilities including cron. Here are more:

  1. last reboot
  2. who -b

Topic starter has many options now.

2015-01-12 12:19 GMT+02:00 Kimball Johnson kimball@bowerham.net:

There is an @reboot cron and similar in system timers - I think they
would be beneficial for this, checking for a shot uptime is likely to be
inconsistent.

Kimball

On 12 January 2015 at 10:13, Sergii Bieliaievskyi <
s.bieliaievskyi@sethq.com> wrote:

Linux has uptime command I think it`s the best way to indicate reboot
happened.
I hope, it will help.

2015-01-12 11:17 GMT+02:00 Sachin Gupta guptasachin1112mrt@gmail.com:

Hi All,

I have an use case where I need to reboot the machine if there is any
new kernel update/install.

I am trying to write an LWRP for reboot handler that can be used in
other recipe's also.

I will be calling linux_reboot once there is an kernel update.

added this code in recipe for reboot:;

  linux_reboot 'kernel updated' do
     action :reboot
       end

resource/reboot.rb

    actions :reboot
      default_action :reboot


    attribute :happened, kind_of: String

    attr_accessor :exists

provider/reboot.rb

def whyrun_supported?
  true
end


action :reboot do

Chef::Log.info "=== Cookbook: #{cookbook_name}"
  Chef::Log.info "=== Resource Name: #{@new_resource.name}"

 if @current_resource.happened
  Chef::Log.info 'Reboot happened'
  else
    converge_by("Reboot system") do
      reboot
    end
  end

end

def load_current_resource
@current_resource = Chef::Resource::linuxReboot.new(@
new_resource.name)
@current_resource.happened = false

begin

search for a file and set the flag..

end

Chef::Log.debug "Reboot debug message"

@current_resource
end

def reboot
Chef::Log.info 'Reboot The Machine'
end


what is the best way to indicate a reboot happened. shall I look for a
file indicating a reboot or something else??
I am thinking to search for a file and if the reboot happened then set
happened=true and return. will this work and is the right approach??

Thanks & Regards,
Sachin Kumar


PRIVILEGED AND CONFIDENTIAL COMMUNICATION
This e-mail transmission, and any documents, files or previous e-mail
messages
attached to it, may contain confidential information that is legally
privileged.

If you are not the intended recipient or a person responsible for
delivering it
to the intended recipient, you are hereby notified that any disclosure,
copying,
distribution or use of any of the information contained in or attached
to this
transmission is strictly prohibited.

If you have received this transmission in error, please: (1) immediately
notify
me by reply e-mail, or by collect telephone call; and (2) destroy the
original
transmission and its attachments without reading or saving in any manner.


PRIVILEGED AND CONFIDENTIAL COMMUNICATION
This e-mail transmission, and any documents, files or previous e-mail
messages
attached to it, may contain confidential information that is legally
privileged.

If you are not the intended recipient or a person responsible for
delivering it
to the intended recipient, you are hereby notified that any disclosure,
copying,
distribution or use of any of the information contained in or attached to
this
transmission is strictly prohibited.

If you have received this transmission in error, please: (1) immediately
notify
me by reply e-mail, or by collect telephone call; and (2) destroy the
original
transmission and its attachments without reading or saving in any manner.

Sergii/Kimball,

Is this the right approach to write an LWRP for reboot handler??

linux_reboot 'kernel updated' do
action :reboot
end

provider/reboot.rb

action :reboot do

Chef::Log.info "=== Cookbook: #{cookbook_name}"
Chef::Log.info '=== Resource: Reboot / Action: reboot'
Chef::Log.info "=== Resource Name: #{@new_resource.name}"

    converge_by("rebooting the system immediately") do
      Chef::Log.warn "Rebooting system immediately, requested by '#{@

new_resource.name}'"
reboot
end

def load_current_resource
@current_resource = Chef::Resource::linuxReboot.new(@new_resource.name)
@current_resource
end

def reboot
Chef::Log.info 'Reboot*************************************'
Mixlib::ShellOut.new(node[:linux][:command]).run_command
end

command is defined in attribute file as

default[:linux][:command] = 'shutdown -r +1&'

Thanks & Regards,
Sachin Kumar

On Sat, Jan 17, 2015 at 12:36 PM, Sachin Gupta <guptasachin1112mrt@gmail.com

wrote:

Hi Sergii/Kimball,

I am able to write reboot handler and this is working fine as expected but
still needs to know whether this is the right approach. this is my first
LWRP..

linux_reboot 'kernel updated' do
action :reboot
end

provider/reboot.rb

action :reboot do

Chef::Log.info "=== Cookbook: #{cookbook_name}"
Chef::Log.info '=== Resource: Reboot / Action: reboot'
Chef::Log.info "=== Resource Name: #{@new_resource.name}"

    converge_by("rebooting the system immediately") do
      Chef::Log.warn "Rebooting system immediately, requested by '#{@

new_resource.name}'"
reboot
end

def load_current_resource
@current_resource = Chef::Resource::linuxReboot.new(@new_resource.name)
@current_resource
end

def reboot
Chef::Log.info 'Reboot*************************************'
Mixlib::ShellOut.new(node[:linux][:command]).run_command
end

command is defined in attribute file as

default[:linux][:command] = 'shutdown -r +1&'

Thanks & Regards,
Sachin Kumar

On Mon, Jan 12, 2015 at 3:58 PM, Sergii Bieliaievskyi <
s.bieliaievskyi@sethq.com> wrote:

There are a lot of possibilities including cron. Here are more:

  1. last reboot
  2. who -b

Topic starter has many options now.

2015-01-12 12:19 GMT+02:00 Kimball Johnson kimball@bowerham.net:

There is an @reboot cron and similar in system timers - I think they
would be beneficial for this, checking for a shot uptime is likely to be
inconsistent.

Kimball

On 12 January 2015 at 10:13, Sergii Bieliaievskyi <
s.bieliaievskyi@sethq.com> wrote:

Linux has uptime command I think it`s the best way to indicate reboot
happened.
I hope, it will help.

2015-01-12 11:17 GMT+02:00 Sachin Gupta guptasachin1112mrt@gmail.com:

Hi All,

I have an use case where I need to reboot the machine if there is any
new kernel update/install.

I am trying to write an LWRP for reboot handler that can be used in
other recipe's also.

I will be calling linux_reboot once there is an kernel update.

added this code in recipe for reboot:;

  linux_reboot 'kernel updated' do
     action :reboot
       end

resource/reboot.rb

    actions :reboot
      default_action :reboot


    attribute :happened, kind_of: String

    attr_accessor :exists

provider/reboot.rb

def whyrun_supported?
  true
end


action :reboot do

Chef::Log.info "=== Cookbook: #{cookbook_name}"
  Chef::Log.info "=== Resource Name: #{@new_resource.name}"

 if @current_resource.happened
  Chef::Log.info 'Reboot happened'
  else
    converge_by("Reboot system") do
      reboot
    end
  end

end

def load_current_resource
@current_resource = Chef::Resource::linuxReboot.new(@
new_resource.name)
@current_resource.happened = false

begin

search for a file and set the flag..

end

Chef::Log.debug "Reboot debug message"

@current_resource
end

def reboot
Chef::Log.info 'Reboot The Machine'
end


what is the best way to indicate a reboot happened. shall I look for a
file indicating a reboot or something else??
I am thinking to search for a file and if the reboot happened then set
happened=true and return. will this work and is the right approach??

Thanks & Regards,
Sachin Kumar


PRIVILEGED AND CONFIDENTIAL COMMUNICATION
This e-mail transmission, and any documents, files or previous e-mail
messages
attached to it, may contain confidential information that is legally
privileged.

If you are not the intended recipient or a person responsible for
delivering it
to the intended recipient, you are hereby notified that any disclosure,
copying,
distribution or use of any of the information contained in or attached
to this
transmission is strictly prohibited.

If you have received this transmission in error, please: (1)
immediately notify
me by reply e-mail, or by collect telephone call; and (2) destroy the
original
transmission and its attachments without reading or saving in any
manner.


PRIVILEGED AND CONFIDENTIAL COMMUNICATION
This e-mail transmission, and any documents, files or previous e-mail
messages
attached to it, may contain confidential information that is legally
privileged.

If you are not the intended recipient or a person responsible for
delivering it
to the intended recipient, you are hereby notified that any disclosure,
copying,
distribution or use of any of the information contained in or attached to
this
transmission is strictly prohibited.

If you have received this transmission in error, please: (1) immediately
notify
me by reply e-mail, or by collect telephone call; and (2) destroy the
original
transmission and its attachments without reading or saving in any manner.

Is there any reason your not using the native reboot resource that Chef
already provides? reboot Resource. As far as I
know you need to be running Chef 12 to use, but if your on an older
version, seems like you could probably use it as a reference.

On Wed, Jan 21, 2015 at 1:15 AM, Sachin Gupta guptasachin1112mrt@gmail.com
wrote:

Sergii/Kimball,

Is this the right approach to write an LWRP for reboot handler??