Class: OsCtld::UserControl::Supervisor

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/user_control/supervisor.rb

Defined Under Namespace

Classes: ClientHandler, NamespacedClientHandler

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



84
85
86
87
# File 'lib/osctld/user_control/supervisor.rb', line 84

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

Instance Method Details

#start_namespacedObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/osctld/user_control/supervisor.rb', line 132

def start_namespaced
  sync do
    path = File.join(RunState::USER_CONTROL_DIR, 'namespaced.sock')
    socket = UNIXServer.new(path)

    File.chown(0, 0, path)
    File.chmod(0666, path)

    s = Generic::Server.new(socket, NamespacedClientHandler)
    t = Thread.new { s.start }

    @servers[:namespaced] = [s, t]
  end
end

#start_server(user) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/osctld/user_control/supervisor.rb', line 106

def start_server(user)
  sync do
    path = socket_path(user)
    socket = UNIXServer.new(path)

    File.chown(0, user.ugid, path)
    File.chmod(0660, path)

    s = Generic::Server.new(socket, ClientHandler, opts: {
      user: user,
    })
    t = Thread.new { s.start }

    @servers[user.name] = [s, t]
  end
end

#stop_allObject



147
148
149
150
151
152
153
154
155
156
# File 'lib/osctld/user_control/supervisor.rb', line 147

def stop_all
  sync do
    @servers.each { |user, st| st[0].stop }
    @servers.each { |user, st| st[1].join }
  end

  s, t = @servers[:namespaced]
  s.stop
  t.join
end

#stop_server(user) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/osctld/user_control/supervisor.rb', line 123

def stop_server(user)
  sync do
    s, t = @servers[user.name]
    s.stop
    t.join
    File.unlink(socket_path(user))
  end
end