Class: OsCtld::AutoStart::State
- Inherits:
-
Object
- Object
- OsCtld::AutoStart::State
show all
- Includes:
- OsCtl::Lib::Utils::File, Lockable
- Defined in:
- lib/osctld/auto_start/state.rb
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) ⇒ State
Returns a new instance of State.
21
22
23
24
25
|
# File 'lib/osctld/auto_start/state.rb', line 21
def initialize(pool)
@pool = pool
@started_cts = []
init_lock
end
|
Instance Attribute Details
10
11
12
|
# File 'lib/osctld/auto_start/state.rb', line 10
def pool
@pool
end
|
#started_cts ⇒ Object
Returns the value of attribute started_cts.
77
78
79
|
# File 'lib/osctld/auto_start/state.rb', line 77
def started_cts
@started_cts
end
|
Class Method Details
14
15
16
17
18
|
# File 'lib/osctld/auto_start/state.rb', line 14
def self.load(pool)
st = new(pool)
st.load
st
end
|
Instance Method Details
#assets(add) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/osctld/auto_start/state.rb', line 28
def assets(add)
add.file(
state_path,
desc: 'Contains a list of auto-started containers',
user: 0,
group: 0,
mode: 0o600,
optional: true
)
end
|
#clear(ct) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/osctld/auto_start/state.rb', line 66
def clear(ct)
exclusively do
next unless started_cts.include?(ct.id)
started_cts.delete(ct.id)
save
end
end
|
#is_started?(ct) ⇒ Boolean
59
60
61
62
63
|
# File 'lib/osctld/auto_start/state.rb', line 59
def is_started?(ct)
inclusively do
started_cts.include?(ct.id)
end
end
|
#load ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/osctld/auto_start/state.rb', line 39
def load
return unless File.exist?(state_path)
File.open(state_path).each_line do |line|
started_cts << line.strip
end
end
|
#save ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/osctld/auto_start/state.rb', line 79
def save
exclusively do
regenerate_file(state_path, 0o600) do |new|
started_cts.each { |id| new.puts(id) }
end
end
end
|
#set_started(ct) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/osctld/auto_start/state.rb', line 48
def set_started(ct)
exclusively do
next if started_cts.include?(ct.id)
started_cts << ct.id
save
end
end
|
#state_path ⇒ Object
87
88
89
|
# File 'lib/osctld/auto_start/state.rb', line 87
def state_path
File.join(pool.autostart_dir, 'started-cts.txt')
end
|