79 lines
2.2 KiB
Ruby
79 lines
2.2 KiB
Ruby
#
|
|
# Cookbook:: esh_lxd
|
|
# Recipe:: setup
|
|
#
|
|
# Copyright:: 2022, https://easyself.host
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# systemd need to be booted with systemd.unified_cgroup_hierarchy=0
|
|
# otherwise, cgroup v1 container cannot be started, only v2
|
|
# and some docker containers use v1
|
|
|
|
#execute 'set systemd boot mode to cgroup v1' do
|
|
# command <<~EOT
|
|
# echo '# use cgroup1' >> /etc/default/grub
|
|
# echo 'GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX systemd.unified_cgroup_hierarchy=0"' \
|
|
# >> /etc/default/grub
|
|
# EOT
|
|
# notifies :run, 'execute[update grub]', :immediately
|
|
# not_if 'grep -q cgroup1 /etc/default/grub'
|
|
#end
|
|
#
|
|
#cgroup = `stat -fc %T /sys/fs/cgroup/`.strip
|
|
#ruby_block 'Check cgroup version' do
|
|
# block do
|
|
# if cgroup == 'cgroup2fs'
|
|
# Chef::Log.fatal('You need to reboot now to enable cgroup v1!')
|
|
# raise 'You need to reboot now to enable cgroup v1!'
|
|
# end
|
|
# end
|
|
# action :run
|
|
#end
|
|
#
|
|
#execute 'update grub' do
|
|
# command 'update-grub2'
|
|
# action :nothing
|
|
#end
|
|
|
|
template '/tmp/lxd.yml' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0644'
|
|
not_if 'lxc storage info nvme'
|
|
action :create
|
|
end
|
|
|
|
execute 'lxd init' do
|
|
command 'lxd init --preseed < /tmp/lxd.yml'
|
|
not_if 'lxc storage info nvme'
|
|
action :run
|
|
end
|
|
|
|
execute 'lxd change images storage location' do
|
|
command <<~EOT
|
|
lxc storage volume create nvme images
|
|
lxc config set storage.images_volume nvme/images
|
|
EOT
|
|
action :run
|
|
not_if 'lxc storage volume info nvme images'
|
|
end
|
|
|
|
unless node['esh']['lxd']['mtu'].nil?
|
|
mtu = node['esh']['lxd']['mtu']
|
|
execute "lxc network set lxdbr0 bridge.mtu #{mtu}" do
|
|
command "lxc network set lxdbr0 bridge.mtu #{mtu}"
|
|
action :run
|
|
not_if "lxc network get lxdbr0 bridge.mtu | grep -q #{mtu}"
|
|
end
|
|
end
|