Class: OsCtld::Daemon

Inherits:
Object
  • Object
show all
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

SOCKET =
File.join(RunState::RUNDIR, 'osctld.sock')
@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Assets::Definition

#define_assets

Class Method Details

.getObject



57
58
59
# File 'lib/osctld/daemon.rb', line 57

def get
  @@instance ||= new
end

Instance Method Details

#assetsObject



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/osctld/daemon.rb', line 110

def assets
  define_assets do |add|
    RunState.assets(add)

    add.socket(
      SOCKET,
      desc: 'Management socket',
      user: 0,
      group: 0,
      mode: 0600
    )
  end
end

#log_typeObject



149
150
151
# File 'lib/osctld/daemon.rb', line 149

def log_type
  'daemon'
end

#serveObject



124
125
126
127
128
129
130
131
132
# File 'lib/osctld/daemon.rb', line 124

def serve
  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

#setupObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/osctld/daemon.rb', line 85

def setup
  # Setup /run/osctl
  RunState.create

  SystemLimits.instance

  # Increase allowed number of open files
  PrLimits.set(Process.pid, PrLimits::NOFILE, 4096, 4096)

  # Setup shared AppArmor files
  AppArmor.setup

  # Migration hooks and server
  Migration.setup

  # Setup network interfaces
  NetInterface.setup

  # Load data pools
  Commands::Pool::Import.run(all: true, autostart: true)

  # Start accepting client commands
  serve
end

#stopObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/osctld/daemon.rb', line 134

def stop
  log(:info, 'Shutting down')
  Eventd.stop
  @server.stop if @server
  File.unlink(SOCKET) if File.exist?(SOCKET)
  UserControl.stop
  Migration.stop
  DB::Pools.get.each { |pool| pool.stop }
  ThreadReaper.stop
  Monitor::Master.stop
  LockRegistry.stop
  log(:info, 'Shutdown successful')
  exit(false)
end