Class: OsCtld::Daemon
- Inherits:
-
Object
- Object
- OsCtld::Daemon
- Includes:
- OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System, Assets::Definition
- Defined in:
- lib/osctld/daemon.rb
Defined Under Namespace
Classes: ClientHandler
Constant Summary collapse
Instance Attribute Summary collapse
- #config ⇒ Config readonly
- #initialized ⇒ Boolean readonly
- #started_at ⇒ Time readonly
Class Method Summary collapse
Instance Method Summary collapse
- #abort_shutdown ⇒ Object
- #abort_shutdown? ⇒ Boolean
- #assets ⇒ Object
- #begin_shutdown ⇒ Object
- #confirm_shutdown ⇒ Object
- #join_server ⇒ Object
- #log_type ⇒ Object
- #serve ⇒ Object
- #setup ⇒ Object
- #shutdown? ⇒ Boolean
- #stop ⇒ Object
- #stopping? ⇒ Boolean
Methods included from Assets::Definition
Instance Attribute Details
#initialized ⇒ Boolean (readonly)
77 78 79 |
# File 'lib/osctld/daemon.rb', line 77 def initialized @initialized end |
#started_at ⇒ Time (readonly)
74 75 76 |
# File 'lib/osctld/daemon.rb', line 74 def started_at @started_at end |
Class Method Details
.create(config) ⇒ Object
59 60 61 62 63 |
# File 'lib/osctld/daemon.rb', line 59 def create(config) fail 'Daemon already instantiated' if @instance @@instance = new(config) end |
.get ⇒ Object
65 66 67 |
# File 'lib/osctld/daemon.rb', line 65 def get @@instance end |
Instance Method Details
#abort_shutdown ⇒ Object
241 242 243 244 245 246 247 248 |
# File 'lib/osctld/daemon.rb', line 241 def abort_shutdown @abort_shutdown = true begin File.unlink(RunState::SHUTDOWN_MARKER) rescue Errno::ENOENT end end |
#abort_shutdown? ⇒ Boolean
262 263 264 |
# File 'lib/osctld/daemon.rb', line 262 def abort_shutdown? @abort_shutdown end |
#assets ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/osctld/daemon.rb', line 182 def assets define_assets do |add| RunState.assets(add) add.socket( SOCKET, desc: 'Management socket', user: 0, group: 0, mode: 0600 ) Devices::V2::BpfProgramCache.assets(add) end end |
#begin_shutdown ⇒ Object
236 237 238 239 |
# File 'lib/osctld/daemon.rb', line 236 def begin_shutdown @abort_shutdown = false File.open(RunState::SHUTDOWN_MARKER, 'w', 0000){} end |
#confirm_shutdown ⇒ Object
250 251 252 253 254 255 256 |
# File 'lib/osctld/daemon.rb', line 250 def confirm_shutdown unless File.exist?(RunState::SHUTDOWN_MARKER) File.open(RunState::SHUTDOWN_MARKER, 'w', 0100){} end File.chmod(0100, RunState::SHUTDOWN_MARKER) end |
#join_server ⇒ Object
210 211 212 |
# File 'lib/osctld/daemon.rb', line 210 def join_server @server_thread.join end |
#log_type ⇒ Object
266 267 268 |
# File 'lib/osctld/daemon.rb', line 266 def log_type 'daemon' end |
#serve ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/osctld/daemon.rb', line 198 def serve @server_thread = Thread.new do log(:info, "Listening on control socket at #{SOCKET}") socket = UNIXServer.new(SOCKET) File.chmod(0600, SOCKET) @server = Generic::Server.new(socket, Daemon::ClientHandler) @server.start end end |
#setup ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/osctld/daemon.rb', line 111 def setup # Setup /run/osctl RunState.create # Open start config start_cfg = RunState.open_start_config SystemLimits.instance CpuScheduler.setup Lxcfs::Scheduler.setup # Increase allowed number of open files PrLimits.set(Process.pid, PrLimits::NOFILE, 131072, 131072) # Setup shared AppArmor files if AppArmor.enabled? log(:info, 'AppArmor enabled') AppArmor.setup else log(:info, 'AppArmor disabled') end # Setup BPF FS BpfFs.setup # User-control supervisor UserControl::Supervisor.instance # Send/Receive hooks and server SendReceive.setup # Setup network interfaces NetInterface.setup # Start accepting client commands serve # Load data pools if KernelParams.import_pools? autostart = KernelParams.autostart_cts? Commands::Pool::Import.run(all: true, autostart: autostart) unless autostart log(:info, 'Container autostart disabled by kernel parameter') end else log(:info, 'Pool autoimport disabled by kernel parameter') end # Resume shutdown if shutdown? log(:info, 'Resuming shutdown') Commands::Self::Shutdown.run elsif start_cfg.activate_lxcfs? log(:info, 'Activating LXCFS') Commands::Self::Activate.run(lxcfs: true) end # Close start config start_cfg.close # All components are up @initialized = true # Wait for the server to finish join_server end |
#shutdown? ⇒ Boolean
258 259 260 |
# File 'lib/osctld/daemon.rb', line 258 def shutdown? File.exist?(RunState::SHUTDOWN_MARKER) end |
#stop ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/osctld/daemon.rb', line 214 def stop @stopping = true log(:info, 'Stopping daemon') Eventd.shutdown @server.stop if @server File.unlink(SOCKET) if File.exist?(SOCKET) UserControl.stop SendReceive.stop DB::Pools.get.each { |pool| pool.stop } Lxcfs::Scheduler.stop CpuScheduler.shutdown ThreadReaper.stop Monitor::Master.stop LockRegistry.stop log(:info, 'Daemon stopped successfully') exit(false) end |
#stopping? ⇒ Boolean
232 233 234 |
# File 'lib/osctld/daemon.rb', line 232 def stopping? @stopping end |