Class: OsCtld::Migration::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/migration/server.rb

Defined Under Namespace

Classes: ClientHandler

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



22
23
24
25
# File 'lib/osctld/migration/server.rb', line 22

def self.instance
  @@instance = new unless @@instance
  @@instance
end

Instance Method Details

#assets(add) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/osctld/migration/server.rb', line 55

def assets(add)
  add.socket(
    Migration::SOCKET,
    desc: 'Socket for migration control',
    user: Migration::UID,
    group: 0,
    mode: 0600
  )
end

#startObject



40
41
42
43
44
45
46
47
# File 'lib/osctld/migration/server.rb', line 40

def start
  socket = UNIXServer.new(Migration::SOCKET)
  File.chown(Migration::UID, 0, Migration::SOCKET)
  File.chmod(0600, Migration::SOCKET)

  @server = Generic::Server.new(socket, ClientHandler)
  @thread = Thread.new { @server.start }
end

#stopObject



49
50
51
52
53
# File 'lib/osctld/migration/server.rb', line 49

def stop
  @server.stop
  @thread.join
  File.unlink(Migration::SOCKET)
end