Class: OsCtld::AutoStart::Reboot

Inherits:
Object
  • Object
show all
Includes:
OsCtl::Lib::Utils::File, Lockable
Defined in:
lib/osctld/auto_start/reboot.rb

Overview

Stores a list of containers that are to be rebooted

Containers can request reboot while osctld is shutting down, e.g. during an update. During this time, we cannot fulfil reboot requests. We instead store them in the runstate and will reboot them when osctld restarts.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Lockable

#exclusively, included, #inclusively, #init_lock, #lock, #unlock

Constructor Details

#initialize(pool) ⇒ Reboot

Returns a new instance of Reboot.

Parameters:



26
27
28
29
30
# File 'lib/osctld/auto_start/reboot.rb', line 26

def initialize(pool)
  @pool = pool
  @reboot_cts = []
  init_lock
end

Instance Attribute Details

#poolPool (readonly)

Returns:



15
16
17
# File 'lib/osctld/auto_start/reboot.rb', line 15

def pool
  @pool
end

#reboot_ctsObject (readonly, protected)

Returns the value of attribute reboot_cts.



97
98
99
# File 'lib/osctld/auto_start/reboot.rb', line 97

def reboot_cts
  @reboot_cts
end

Class Method Details

.load(pool) ⇒ AutoStart::Reboot

Parameters:

Returns:



19
20
21
22
23
# File 'lib/osctld/auto_start/reboot.rb', line 19

def self.load(pool)
  st = new(pool)
  st.load
  st
end

Instance Method Details

#add(ct) ⇒ Object

Parameters:



55
56
57
58
59
60
61
62
63
64
# File 'lib/osctld/auto_start/reboot.rb', line 55

def add(ct)
  exclusively do
    next if reboot_cts.include?(ct.id)

    reboot_cts << ct.id
    save
  end

  nil
end

#assets(add) ⇒ Object

Parameters:



33
34
35
36
37
38
39
40
41
42
# File 'lib/osctld/auto_start/reboot.rb', line 33

def assets(add)
  add.file(
    state_path,
    desc: 'Contains a list of containers to reboot',
    user: 0,
    group: 0,
    mode: 0o600,
    optional: true
  )
end

#clear(ct) ⇒ Object

Parameters:



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/osctld/auto_start/reboot.rb', line 74

def clear(ct)
  exclusively do
    i = reboot_cts.index(ct.id)
    next if i.nil?

    reboot_cts.delete_at(i)
    save
  end

  nil
end

#clear_allObject



86
87
88
89
90
91
92
93
# File 'lib/osctld/auto_start/reboot.rb', line 86

def clear_all
  exclusively do
    reboot_cts.clear
    save
  end

  nil
end

#include?(ct) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/osctld/auto_start/reboot.rb', line 67

def include?(ct)
  inclusively do
    reboot_cts.include?(ct.id)
  end
end

#loadObject



44
45
46
47
48
49
50
51
52
# File 'lib/osctld/auto_start/reboot.rb', line 44

def load
  return unless File.exist?(state_path)

  File.open(state_path).each_line do |line|
    reboot_cts << line.strip
  end

  nil
end

#saveObject (protected)



99
100
101
102
103
104
105
# File 'lib/osctld/auto_start/reboot.rb', line 99

def save
  exclusively do
    regenerate_file(state_path, 0o600) do |new|
      reboot_cts.each { |id| new.puts(id) }
    end
  end
end

#state_pathObject (protected)



107
108
109
# File 'lib/osctld/auto_start/reboot.rb', line 107

def state_path
  File.join(pool.autostart_dir, 'reboot-cts.txt')
end