Class: OsCtld::Pool

Inherits:
Object
  • Object
show all
Includes:
OsCtl::Lib::Utils::Exception, OsCtl::Lib::Utils::File, OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System, Assets::Definition, Lockable, Manipulable
Defined in:
lib/osctld/pool.rb

Overview

This class represents a data pool

Data pool contains users, groups and containers, both data and configuration. Each user/group/ct belongs to exactly one pool.

Defined Under Namespace

Modules: Hooks

Constant Summary collapse

PROPERTY_ACTIVE =
'org.vpsadminos.osctl:active'.freeze
PROPERTY_DATASET =
'org.vpsadminos.osctl:dataset'.freeze
CT_DS =
'ct'.freeze
CONF_DS =
'conf'.freeze
HOOK_DS =
'hook'.freeze
LOG_DS =
'log'.freeze
REPOSITORY_DS =
'repository'.freeze
MIGRATION_DS =
'migration'.freeze
TRASH_BIN_DS =
'trash'.freeze
OPTIONS =
%i[parallel_start parallel_stop].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assets::Definition

#define_assets

Methods included from Manipulable

#acquire_manipulation_lock, #init_manipulable, #is_being_manipulated?, #manipulate, #manipulated_by, #release_manipulation_lock

Methods included from Lockable

#exclusively, included, #inclusively, #init_lock, #lock, #unlock

Constructor Details

#initialize(name, dataset) ⇒ Pool

Returns a new instance of Pool.



36
37
38
39
40
41
42
43
44
45
# File 'lib/osctld/pool.rb', line 36

def initialize(name, dataset)
  init_lock
  init_manipulable

  @name = name
  @dataset = dataset || name
  @state = :importing
  @attrs = Attributes.new
  @abort_export = false
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



33
34
35
# File 'lib/osctld/pool.rb', line 33

def attrs
  @attrs
end

#autostart_planObject (readonly)

Returns the value of attribute autostart_plan.



33
34
35
# File 'lib/osctld/pool.rb', line 33

def autostart_plan
  @autostart_plan
end

#autostop_planObject (readonly)

Returns the value of attribute autostop_plan.



33
34
35
# File 'lib/osctld/pool.rb', line 33

def autostop_plan
  @autostop_plan
end

#datasetObject (readonly)

Returns the value of attribute dataset.



33
34
35
# File 'lib/osctld/pool.rb', line 33

def dataset
  @dataset
end

#nameObject (readonly)

Returns the value of attribute name.



33
34
35
# File 'lib/osctld/pool.rb', line 33

def name
  @name
end

#send_receive_key_chainObject (readonly)

Returns the value of attribute send_receive_key_chain.



33
34
35
# File 'lib/osctld/pool.rb', line 33

def send_receive_key_chain
  @send_receive_key_chain
end

#stateObject (readonly)

Returns the value of attribute state.



33
34
35
# File 'lib/osctld/pool.rb', line 33

def state
  @state
end

#trash_binObject (readonly)

Returns the value of attribute trash_bin.



33
34
35
# File 'lib/osctld/pool.rb', line 33

def trash_bin
  @trash_bin
end

Instance Method Details

#abort_exportObject



420
421
422
423
# File 'lib/osctld/pool.rb', line 420

def abort_export
  @abort_export = true
  autostop_plan.clear
end

#abort_export?Boolean

Returns:

  • (Boolean)


425
426
427
# File 'lib/osctld/pool.rb', line 425

def abort_export?
  @abort_export
end

#active?Boolean

Returns:

  • (Boolean)


429
430
431
# File 'lib/osctld/pool.rb', line 429

def active?
  state == :active
end

#all_stopObject



406
407
408
409
# File 'lib/osctld/pool.rb', line 406

def all_stop
  autostop_plan.stop
  @hint_updater.stop
end

#apparmor_dirObject



509
510
511
# File 'lib/osctld/pool.rb', line 509

def apparmor_dir
  File.join(run_dir, 'apparmor')
end

#assetsObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/osctld/pool.rb', line 67

def assets
  define_assets do |add|
    # Datasets
    add.dataset(
      ds(CT_DS),
      desc: 'Contains container root filesystems',
      user: 0,
      group: 0,
      mode: 0o511
    )
    add.dataset(
      ds(CONF_DS),
      desc: 'Configuration files',
      user: 0,
      group: 0,
      mode: 0o500
    )
    add.dataset(
      ds(HOOK_DS),
      desc: 'User supplied script hooks',
      user: 0,
      group: 0,
      mode: 0o500
    )
    add.dataset(
      ds(LOG_DS),
      desc: 'Container log files, pool history',
      user: 0,
      group: 0,
      mode: 0o511
    )
    add.dataset(
      ds(REPOSITORY_DS),
      desc: 'Local image repository cache',
      user: Repository::UID,
      group: 0,
      mode: 0o500
    )
    add.dataset(
      ds(MIGRATION_DS),
      desc: 'Data for OS migrations',
      user: 0,
      group: 0,
      mode: 0o500
    )
    add.dataset(
      ds(TRASH_BIN_DS),
      desc: 'Trash bin',
      user: 0,
      group: 0,
      mode: 0o500
    )

    # Configs
    add.directory(
      File.join(conf_path, 'pool'),
      desc: 'Pool configuration files for osctld',
      user: 0,
      group: 0,
      mode: 0o500
    )
    add.file(
      config_path,
      desc: 'Pool configuration file for osctld',
      optional: true
    )
    add.directory(
      File.join(conf_path, 'user'),
      desc: 'User configuration files for osctld',
      user: 0,
      group: 0,
      mode: 0o500
    )
    add.directory(
      File.join(conf_path, 'group'),
      desc: 'Group configuration files for osctld',
      user: 0,
      group: 0,
      mode: 0o500
    )
    add.directory(
      File.join(conf_path, 'ct'),
      desc: 'Container configuration files for osctld',
      user: 0,
      group: 0,
      mode: 0o500
    )
    add.directory(
      File.join(conf_path, 'send-receive'),
      desc: 'Identity and authorized keys for container send/receive',
      user: 0,
      group: 0,
      mode: 0o500
    )
    add.directory(
      File.join(conf_path, 'repository'),
      desc: 'Repository configuration files for osctld',
      user: 0,
      group: 0,
      mode: 0o500
    )
    add.directory(
      File.join(conf_path, 'id-range'),
      desc: 'ID range configuration files for osctld',
      user: 0,
      group: 0,
      mode: 0o500
    )

    # Logs
    add.directory(
      File.join(log_path, 'ct'),
      desc: 'Container log files',
      user: 0,
      group: 0
    )

    # Hooks
    add.directory(
      File.join(user_hook_script_dir),
      desc: 'User supplied pool script hooks',
      user: 0,
      group: 0
    )
    add.directory(
      File.join(root_user_hook_script_dir, 'ct'),
      desc: 'User supplied container script hooks',
      user: 0,
      group: 0
    )

    # Pool history
    History.assets(pool, add)

    # Send/Receive
    send_receive_key_chain.assets(add)

    # Runstate
    add.directory(
      run_dir,
      desc: 'Runtime configuration',
      user: 0,
      group: 0,
      mode: 0o711
    )
    add.directory(
      user_dir,
      desc: 'Contains user homes and LXC configuration',
      user: 0,
      group: 0,
      mode: 0o511
    )
    add.directory(
      ct_dir,
      desc: 'Contains runtime container state data',
      user: 0,
      group: 0,
      mode: 0o700
    )
    add.directory(
      console_dir,
      desc: 'Sockets for container consoles',
      user: 0,
      group: 0,
      mode: 0o711
    )
    add.directory(
      hook_dir,
      desc: 'Container hooks',
      user: 0,
      group: 0,
      mode: 0o711
    )
    add.directory(
      mount_dir,
      desc: 'Mount helper directories for containers',
      user: 0,
      group: 0,
      mode: 0o711
    )

    if AppArmor.enabled?
      add.directory(
        apparmor_dir,
        desc: 'AppArmor files',
        user: 0,
        group: 0,
        mode: 0o700
      )

      AppArmor.assets(add, pool)
    end

    add.directory(
      autostart_dir,
      desc: 'Contains runtime container auto-start state',
      user: 0,
      group: 0,
      mode: 0o700
    )

    autostart_plan.assets(add) if autostart_plan
  end
end

#autostart(force: false) ⇒ Object



375
376
377
378
# File 'lib/osctld/pool.rb', line 375

def autostart(force: false)
  Hook.run(self, :pre_autostart)
  autostart_plan.start(force:)
end

#autostart_dirObject



493
494
495
# File 'lib/osctld/pool.rb', line 493

def autostart_dir
  File.join(run_dir, 'auto-start')
end

#autostop_and_wait(message: nil, client_handler: nil) ⇒ Object



380
381
382
383
# File 'lib/osctld/pool.rb', line 380

def autostop_and_wait(message: nil, client_handler: nil)
  autostop_plan.start(message:, client_handler:)
  autostop_plan.wait
end

#autostop_no_wait(message: nil, client_handler: nil, progress_tracker: nil) ⇒ Object



385
386
387
# File 'lib/osctld/pool.rb', line 385

def autostop_no_wait(message: nil, client_handler: nil, progress_tracker: nil)
  autostop_plan.start(message:, client_handler:, progress_tracker:)
end

#begin_exportObject



416
417
418
# File 'lib/osctld/pool.rb', line 416

def begin_export
  @abort_export = false
end

#begin_stopObject



401
402
403
404
# File 'lib/osctld/pool.rb', line 401

def begin_stop
  autostart_plan.stop if autostart_plan.started?
  trash_bin.stop if trash_bin.started?
end

#check_user_conflict(user) ⇒ Object (protected)



767
768
769
770
771
772
773
774
775
776
777
778
779
780
# File 'lib/osctld/pool.rb', line 767

def check_user_conflict(user)
  DB::Users.sync do
    if (u = DB::Users.by_ugid(user.ugid))
      log(
        :warn,
        "Unable to load user '#{user.name}': " \
        "user/group ID #{user.ugid} already taken by pool '#{u.pool.name}'"
      )
      return false
    end
  end

  true
end

#conf_pathObject



453
454
455
# File 'lib/osctld/pool.rb', line 453

def conf_path
  path(CONF_DS)
end

#config_pathObject



513
514
515
# File 'lib/osctld/pool.rb', line 513

def config_path
  File.join(conf_path, 'pool', 'config.yml')
end

#console_dirObject



501
502
503
# File 'lib/osctld/pool.rb', line 501

def console_dir
  File.join(run_dir, 'console')
end

#ct_dirObject



489
490
491
# File 'lib/osctld/pool.rb', line 489

def ct_dir
  File.join(run_dir, 'containers')
end

#ct_dsObject



445
446
447
# File 'lib/osctld/pool.rb', line 445

def ct_ds
  ds(CT_DS)
end

#default_optsObject (protected)



537
538
539
540
541
542
# File 'lib/osctld/pool.rb', line 537

def default_opts
  {
    parallel_start: 2,
    parallel_stop: 4
  }
end

#disableObject



441
442
443
# File 'lib/osctld/pool.rb', line 441

def disable
  @state = :disabled
end

#disabled?Boolean

Returns:

  • (Boolean)


437
438
439
# File 'lib/osctld/pool.rb', line 437

def disabled?
  state == :disabled
end

#ds(path) ⇒ Object (protected)



788
789
790
# File 'lib/osctld/pool.rb', line 788

def ds(path)
  File.join(dataset, path)
end

#dump_optsObject (protected)



544
545
546
547
548
549
550
551
552
553
# File 'lib/osctld/pool.rb', line 544

def dump_opts
  ret = {}

  OPTIONS.each do |k|
    v = instance_variable_get("@#{k}")
    ret[k.to_s] = v unless v.nil?
  end

  ret
end

#ensure_limits(ct) ⇒ Object (protected)



782
783
784
785
786
# File 'lib/osctld/pool.rb', line 782

def ensure_limits(ct)
  return unless ct.prlimits.contains?('nofile')

  SystemLimits.ensure_nofile(ct.prlimits['nofile'].hard)
end

#fulfil_reboot(ct) ⇒ Object



397
398
399
# File 'lib/osctld/pool.rb', line 397

def fulfil_reboot(ct)
  autostart_plan.fulfil_reboot(ct)
end

#hook_dirObject



497
498
499
# File 'lib/osctld/pool.rb', line 497

def hook_dir
  File.join(run_dir, 'hooks')
end

#idObject



59
60
61
# File 'lib/osctld/pool.rb', line 59

def id
  name
end

#imported?Boolean

Returns:

  • (Boolean)


433
434
435
# File 'lib/osctld/pool.rb', line 433

def imported?
  state != :importing
end

#initObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/osctld/pool.rb', line 47

def init
  exclusively do
    load_config

    @send_receive_key_chain = SendReceive::KeyChain.new(self)
    @autostart_plan = AutoStart::Plan.new(self)
    @autostop_plan = AutoStop::Plan.new(self)
    @trash_bin = TrashBin.new(self)
    @hint_updater = HintUpdater.new(self)
  end
end

#load_configObject (protected)



527
528
529
530
531
532
533
534
535
# File 'lib/osctld/pool.rb', line 527

def load_config
  return unless File.exist?(config_path)

  cfg = OsCtl::Lib::ConfigFile.load_yaml_file(config_path)

  @parallel_start = cfg['parallel_start']
  @parallel_stop = cfg['parallel_stop']
  @attrs = Attributes.load(cfg['attrs'] || {})
end

#load_ctsObject (protected)



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
# File 'lib/osctld/pool.rb', line 655

def load_cts
  log(:info, 'Loading containers')

  ds_cache = OsCtl::Lib::Zfs::DatasetCache.new(
    OsCtl::Lib::Zfs::Dataset.new(ds(CT_DS)).list(properties: %w[name mountpoint])
  )

  ep = ExecutionPlan.new

  Dir.glob(File.join(conf_path, 'ct', '*.yml')).each do |f|
    ep << File.basename(f)[0..(('.yml'.length + 1) * -1)]
  end

  log(:info, "Going to load #{ep.length} containers, #{ep.default_threads} at a time")

  ep.run do |ctid|
    log(:info, "Loading container #{ctid}")

    ct = load_entity('container', ctid) do
      Container.new(self, ctid, nil, nil, nil, dataset_cache: ds_cache)
    end
    next unless ct

    ensure_limits(ct)

    builder = Container::Builder.new(ct.get_run_conf)
    builder.setup_lxc_home
    builder.setup_log_file

    ct.reconfigure

    running = ct.fresh_state == :running

    ct.ensure_run_conf if running
    Monitor::Master.monitor(ct)
    Console.reconnect_tty0(ct) if running

    DB::Containers.add(ct)
  end

  ep.wait
  log(:info, 'All containers loaded')
end

#load_entity(type, name) ⇒ Object (protected)



714
715
716
717
718
719
720
721
722
723
724
725
# File 'lib/osctld/pool.rb', line 714

def load_entity(type, name)
  yield
rescue ConfigError => e
  if e.original_exception
    log(:fatal, "#{type} #{name}: #{e.message}: #{e.original_exception.message} (#{e.original_exception.class})")
    log(:fatal, denixstorify(e.original_exception.backtrace).join("\n"))
  else
    log(:fatal, "Unable to load config of #{type} #{name}: #{e.message}")
  end

  nil
end

#load_groupsObject (protected)



624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/osctld/pool.rb', line 624

def load_groups
  log(:info, 'Loading groups')
  DB::Groups.setup(self)

  rx = %r{^#{Regexp.escape(File.join(conf_path, 'group'))}(.*)/config\.yml$}

  Dir.glob(File.join(conf_path, 'group', '**', 'config.yml')).each do |file|
    next unless rx =~ file

    name = ::Regexp.last_match(1)
    next if ['', '/default'].include?(name)

    grp = load_entity('group', name) do
      Group.new(self, name, devices: false)
    end
    next unless grp

    DB::Groups.add(grp)
  end

  # The devices in the root group have to be configured as soon as possible,
  # because `echo a > devices.deny` will not work when the root cgroup has
  # any children.
  root = DB::Groups.root(self)

  # Initialize devices of all groups, from the root group down
  root.descendants.each do |grp|
    grp.devices.init
  end
end

#load_id_rangesObject (protected)



597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'lib/osctld/pool.rb', line 597

def load_id_ranges
  log(:info, 'Loading ID ranges')
  DB::IdRanges.setup(self)

  Dir.glob(File.join(conf_path, 'id-range', '*.yml')).each do |f|
    name = File.basename(f)[0..(('.yml'.length + 1) * -1)]
    next if name == 'default'

    range = load_entity('id-range', name) { IdRange.new(self, name) }
    next unless range

    DB::IdRanges.add(range)
  end
end

#load_repositoriesObject (protected)



699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'lib/osctld/pool.rb', line 699

def load_repositories
  log(:info, 'Loading repositories')
  DB::Repositories.setup(self)

  Dir.glob(File.join(conf_path, 'repository', '*.yml')).each do |f|
    name = File.basename(f)[0..(('.yml'.length + 1) * -1)]
    next if name == 'default'

    repo = load_entity('repository', name) { Repository.new(self, name) }
    next unless repo

    DB::Repositories.add(repo)
  end
end

#load_usersObject (protected)



612
613
614
615
616
617
618
619
620
621
622
# File 'lib/osctld/pool.rb', line 612

def load_users
  log(:info, 'Loading users')

  Dir.glob(File.join(conf_path, 'user', '*.yml')).each do |f|
    name = File.basename(f)[0..(('.yml'.length + 1) * -1)]
    u = load_entity('user', name) { User.new(self, name) }
    next if !u || !check_user_conflict(u)

    Commands::User::Setup.run!(user: u)
  end
end

#log_pathObject



457
458
459
# File 'lib/osctld/pool.rb', line 457

def log_path
  path(LOG_DS)
end

#log_typeObject



473
474
475
# File 'lib/osctld/pool.rb', line 473

def log_type
  "pool=#{name}"
end

#manipulation_resourceObject



477
478
479
# File 'lib/osctld/pool.rb', line 477

def manipulation_resource
  ['pool', name]
end

#mkdatasetsObject (protected)



561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/osctld/pool.rb', line 561

def mkdatasets
  log(:info, 'Ensuring presence of base datasets and directories')
  zfs(:create, '-p', ds(CT_DS))
  zfs(:create, '-p', ds(CONF_DS))
  zfs(:create, '-p', ds(HOOK_DS))
  zfs(:create, '-p', ds(LOG_DS))
  zfs(:create, '-p', ds(REPOSITORY_DS))
  zfs(:create, '-p', ds(MIGRATION_DS))
  zfs(:create, '-p', ds(TRASH_BIN_DS))

  File.chmod(0o511, path(CT_DS))
  File.chmod(0o500, path(CONF_DS))
  File.chmod(0o500, path(HOOK_DS))
  File.chmod(0o511, path(LOG_DS))

  File.chown(Repository::UID, 0, path(REPOSITORY_DS))
  File.chmod(0o500, path(REPOSITORY_DS))

  File.chmod(0o500, path(MIGRATION_DS))
  File.chmod(0o500, path(TRASH_BIN_DS))

  # Configuration directories
  %w[pool ct group user send-receive repository id-range].each do |dir|
    path = File.join(conf_path, dir)
    FileUtils.mkdir_p(path, mode: 0o500)
  end

  [
    File.join(root_user_hook_script_dir, 'ct'),
    user_hook_script_dir,
    File.join(log_path, 'ct')
  ].each do |path|
    FileUtils.mkdir_p(path)
  end
end

#mount_dirObject



505
506
507
# File 'lib/osctld/pool.rb', line 505

def mount_dir
  File.join(run_dir, 'mounts')
end

#path(ds = '') ⇒ Object (protected)



792
793
794
# File 'lib/osctld/pool.rb', line 792

def path(ds = '')
  File.join('/', dataset, ds)
end

#poolObject



63
64
65
# File 'lib/osctld/pool.rb', line 63

def pool
  self
end

#repo_pathObject



469
470
471
# File 'lib/osctld/pool.rb', line 469

def repo_path
  path(REPOSITORY_DS)
end

#request_reboot(ct) ⇒ Object



393
394
395
# File 'lib/osctld/pool.rb', line 393

def request_reboot(ct)
  autostart_plan.request_reboot(ct)
end

#root_user_hook_script_dirObject



461
462
463
# File 'lib/osctld/pool.rb', line 461

def root_user_hook_script_dir
  path(HOOK_DS)
end

#run_dirObject



481
482
483
# File 'lib/osctld/pool.rb', line 481

def run_dir
  File.join(RunState::POOL_DIR, name)
end

#runstateObject (protected)



727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/osctld/pool.rb', line 727

def runstate
  FileUtils.mkdir_p(run_dir, mode: 0o711)

  if Dir.exist?(user_dir)
    File.chmod(0o511, user_dir)
  else
    Dir.mkdir(user_dir, 0o511)
  end
  File.chown(0, 0, user_dir)

  [console_dir, hook_dir, mount_dir].each do |dir|
    FileUtils.mkdir_p(dir, mode: 0o711)
  end

  [ct_dir, apparmor_dir, autostart_dir].each do |dir|
    FileUtils.mkdir_p(dir, mode: 0o700)
  end

  %w[
    ct-pre-start
    ct-pre-mount
    ct-post-mount
    ct-autodev
    ct-on-start
    ct-post-stop
  ].each do |hook|
    symlink = OsCtld.hook_run(hook, self)
    hook_src = OsCtld.hook_src(hook)

    if File.symlink?(symlink)
      next if File.readlink(symlink) == hook_src

      File.unlink(symlink)

    end

    File.symlink(hook_src, symlink)
  end
end

#save_configObject (protected)



555
556
557
558
559
# File 'lib/osctld/pool.rb', line 555

def save_config
  regenerate_file(config_path, 0o400) do |f|
    f.write(OsCtl::Lib::ConfigFile.dump_yaml(dump_opts.merge(attrs.dump)))
  end
end

#set(opts) ⇒ Object

Set pool options

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :parallel_start (Integer)
  • :parallel_stop (Integer)
  • :attrs (Hash)


331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/osctld/pool.rb', line 331

def set(opts)
  opts.each do |k, v|
    case k
    when :parallel_start
      instance_variable_set(:"@#{k}", opts[k])
      pool.autostart_plan.resize(opts[k])

    when :parallel_stop
      instance_variable_set(:"@#{k}", opts[k])
      pool.autostop_plan.resize(opts[k])

    when :attrs
      attrs.update(v)

    else
      raise "unsupported option '#{k}'"
    end
  end

  save_config
end

#setupObject



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/osctld/pool.rb', line 272

def setup
  # Ensure needed datasets are present
  mkdatasets

  # Setup run state, i.e. hooks
  runstate

  # Load ID ranges
  load_id_ranges

  # Load users from zpool
  load_users

  # Register loaded users into the system
  Commands::User::Register.run(all: true)

  # Generate /etc/subuid and /etc/subgid
  Commands::User::SubUGIds.run

  # Setup BPF FS
  BpfFs.add_pool(name)
  Devices::V2::BpfProgramCache.load_links(name)

  # Load groups
  load_groups

  # Load containers from zpool
  load_cts

  # Setup AppArmor profiles
  AppArmor.setup_pool(pool) if AppArmor.enabled?

  # Allow containers to create veth interfaces
  Commands::User::LxcUsernet.run

  # Load send/receive keys
  send_receive_key_chain.setup
  SendReceive.deploy

  # Load repositories
  load_repositories

  # Open history
  History.open(self)

  # Start trash-bin GC
  trash_bin.start

  exclusively { @state = :active }

  # Schedule hint updates
  @hint_updater.start
end

#stopObject



411
412
413
414
# File 'lib/osctld/pool.rb', line 411

def stop
  begin_stop
  all_stop
end

#trash_bin_dsObject



449
450
451
# File 'lib/osctld/pool.rb', line 449

def trash_bin_ds
  ds(TRASH_BIN_DS)
end

#unset(opts) ⇒ Object

Reset pool options

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :options (Array<Symbol>)
  • :attrs (Array<String>)


357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/osctld/pool.rb', line 357

def unset(opts)
  opts.each do |k, v|
    case k
    when :options
      OPTIONS.each do |opt|
        next unless v.include?(opt)

        remove_instance_variable(:"@#{opt}")
      end

    when :attrs
      v.each { |attr| attrs.unset(attr) }
    end
  end

  save_config
end

#user_dirObject



485
486
487
# File 'lib/osctld/pool.rb', line 485

def user_dir
  File.join(run_dir, 'users')
end

#user_hook_script_dirObject



465
466
467
# File 'lib/osctld/pool.rb', line 465

def user_hook_script_dir
  File.join(root_user_hook_script_dir, 'pool')
end

#wait_for_autostopObject



389
390
391
# File 'lib/osctld/pool.rb', line 389

def wait_for_autostop
  autostop_plan.wait
end