Class: OsCtld::DistConfig::Distributions::Guix

Inherits:
Base
  • Object
show all
Defined in:
lib/osctld/dist_config/distributions/guix.rb

Defined Under Namespace

Classes: Configurator

Instance Attribute Summary

Attributes inherited from Base

#configurator, #ct, #ctrc, #distribution, #version

Instance Method Summary collapse

Methods inherited from Base

#add_netif, #apply_hostname, #configurator_class, distribution, #dns_resolvers, #initialize, #log_type, #network, #post_mount, #pre_start, #remove_netif, #rename_netif, #set_hostname, #start, #unset_etc_hosts, #update_etc_hosts, #volatile_is_systemd?, #with_rootfs

Methods included from Utils::SwitchUser

#ct_attach, #ct_syscmd

Constructor Details

This class inherits a constructor from OsCtld::DistConfig::Distributions::Base

Instance Method Details

#bin_path(_opts) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/osctld/dist_config/distributions/guix.rb', line 105

def bin_path(_opts)
  with_rootfs do
    File.realpath('/var/guix/profiles/system/profile/bin')
  rescue Errno::ENOENT
    '/bin'
  end
end

#passwd(opts) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/osctld/dist_config/distributions/guix.rb', line 90

def passwd(opts)
  # Without the -c switch, the password is not set (bug?)
  ret = ct_syscmd(
    ct,
    %w[chpasswd -c SHA512],
    stdin: "#{opts[:user]}:#{opts[:password]}\n",
    run: true,
    valid_rcs: :all
  )

  return true if ret.success?

  log(:warn, ct, "Unable to set password: #{ret.output}")
end

#stop(opts) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/osctld/dist_config/distributions/guix.rb', line 36

def stop(opts)
  return super unless %i[stop shutdown].include?(opts[:mode])

  wait_until = Time.now + opts[:timeout]
  stopped = false
  event_queue = Eventd.subscribe

  # Shepherd gets stuck when it is sent a signal, so shut it down only using
  # halt.
  halt_thread = Thread.new do
    ContainerControl::Commands::StopByHalt.run!(
      ct,
      message: opts[:message]
    )
  rescue ContainerControl::Error => e
    log(:warn, ct, "Unable to gracefully shutdown shepherd: #{e.message}")
  end

  loop do
    unless ct.running?
      stopped = true
      break
    end

    timeout = wait_until - Time.now
    break if timeout < 0

    event = event_queue.pop(timeout:)
    break if event.nil?

    # Ignore irrelevant events
    next if event.type != :state \
            || event.opts[:pool] != ct.pool.name \
            || event.opts[:id] != ct.id

    if event.opts[:state] == :stopped
      stopped = true
      break
    end
  end

  Eventd.unsubscribe(event_queue)

  if !stopped && opts[:mode] != :shutdown
    log(:debug, ct, 'Timeout while waiting for graceful shutdown, killing the container')
    super(opts.merge(mode: :kill, message: nil))
  elsif ct.running?
    halt_thread.terminate
    raise ContainerControl::Error, 'Timeout while waiting for halt'
  end

  halt_thread.join
end