mirror of
https://github.com/YunoHost-Apps/yunorunner_ynh.git
synced 2024-09-03 20:36:13 +02:00
Use a config file instead of hard coded string
This commit is contained in:
parent
f794c09af2
commit
42db2ac21b
2 changed files with 54 additions and 61 deletions
44
conf/lxd-preseed.yml
Normal file
44
conf/lxd-preseed.yml
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
config:
|
||||||
|
cluster.https_address: __DOMAIN__:8443
|
||||||
|
core.https_address: __DOMAIN__:8443
|
||||||
|
core.trust_password: __YUNO_PWD__
|
||||||
|
networks:
|
||||||
|
- config:
|
||||||
|
ipv4.address: 192.168.__LXC_NETWORK__.1/24
|
||||||
|
ipv4.nat: "true"
|
||||||
|
ipv6.address: none
|
||||||
|
description: ""
|
||||||
|
name: lxdbr0
|
||||||
|
type: bridge
|
||||||
|
project: default
|
||||||
|
storage_pools:
|
||||||
|
- config:
|
||||||
|
size: __BTRFS_SIZE__GB
|
||||||
|
source: /var/lib/lxd/disks/local.img
|
||||||
|
description: ""
|
||||||
|
name: local
|
||||||
|
driver: btrfs
|
||||||
|
profiles:
|
||||||
|
- config: {}
|
||||||
|
description: Default LXD profile
|
||||||
|
devices:
|
||||||
|
lxdbr0:
|
||||||
|
nictype: bridged
|
||||||
|
parent: lxdbr0
|
||||||
|
type: nic
|
||||||
|
root:
|
||||||
|
path: /
|
||||||
|
pool: local
|
||||||
|
type: disk
|
||||||
|
name: default
|
||||||
|
projects:
|
||||||
|
- config:
|
||||||
|
features.images: "true"
|
||||||
|
features.networks: "true"
|
||||||
|
features.profiles: "true"
|
||||||
|
features.storage.volumes: "true"
|
||||||
|
description: Default LXD project
|
||||||
|
name: default
|
||||||
|
cluster:
|
||||||
|
server_name: __DOMAIN__
|
||||||
|
enabled: true
|
|
@ -29,7 +29,16 @@ setup_lxd() {
|
||||||
ynh_print_info "Configuring lxd..."
|
ynh_print_info "Configuring lxd..."
|
||||||
|
|
||||||
if [ "$cluster" -eq 1 ]; then
|
if [ "$cluster" -eq 1 ]; then
|
||||||
setup_lxd
|
yunohost firewall allow TCP 8443
|
||||||
|
|
||||||
|
free_space=$(df --output=avail / | sed 1d)
|
||||||
|
btrfs_size=$(( free_space * 90 / 100 / 1024 / 1024 ))
|
||||||
|
lxc_network=$((1 + RANDOM % 254))
|
||||||
|
ynh_add_config --template="lxd-preseed.yml" --destination="$install_dir/lxd-preseed.yml"
|
||||||
|
lxd init --preseed < "$install_dir/lxd-preseed.yml"
|
||||||
|
rm "$install_dir/lxd-preseed.yml"
|
||||||
|
|
||||||
|
lxc config set core.https_address "[::]"
|
||||||
else
|
else
|
||||||
lxd init --auto # --storage-backend=dir
|
lxd init --auto # --storage-backend=dir
|
||||||
fi
|
fi
|
||||||
|
@ -46,66 +55,6 @@ exposed_ports_if_cluster() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_lxd_cluster() {
|
|
||||||
local free_space=$(df --output=avail / | sed 1d)
|
|
||||||
local btrfs_size=$(( free_space * 90 / 100 / 1024 / 1024 ))
|
|
||||||
local lxc_network=$((1 + RANDOM % 254))
|
|
||||||
|
|
||||||
yunohost firewall allow TCP 8443
|
|
||||||
|
|
||||||
tmpfile=$(mktemp --suffix=.preseed.yml)
|
|
||||||
cat >"$tmpfile" <<EOF
|
|
||||||
config:
|
|
||||||
cluster.https_address: $domain:8443
|
|
||||||
core.https_address: ${domain}:8443
|
|
||||||
core.trust_password: ${yuno_pwd}
|
|
||||||
networks:
|
|
||||||
- config:
|
|
||||||
ipv4.address: 192.168.${lxc_network}.1/24
|
|
||||||
ipv4.nat: "true"
|
|
||||||
ipv6.address: none
|
|
||||||
description: ""
|
|
||||||
name: lxdbr0
|
|
||||||
type: bridge
|
|
||||||
project: default
|
|
||||||
storage_pools:
|
|
||||||
- config:
|
|
||||||
size: ${btrfs_size}GB
|
|
||||||
source: /var/lib/lxd/disks/local.img
|
|
||||||
description: ""
|
|
||||||
name: local
|
|
||||||
driver: btrfs
|
|
||||||
profiles:
|
|
||||||
- config: {}
|
|
||||||
description: Default LXD profile
|
|
||||||
devices:
|
|
||||||
lxdbr0:
|
|
||||||
nictype: bridged
|
|
||||||
parent: lxdbr0
|
|
||||||
type: nic
|
|
||||||
root:
|
|
||||||
path: /
|
|
||||||
pool: local
|
|
||||||
type: disk
|
|
||||||
name: default
|
|
||||||
projects:
|
|
||||||
- config:
|
|
||||||
features.images: "true"
|
|
||||||
features.networks: "true"
|
|
||||||
features.profiles: "true"
|
|
||||||
features.storage.volumes: "true"
|
|
||||||
description: Default LXD project
|
|
||||||
name: default
|
|
||||||
cluster:
|
|
||||||
server_name: ${domain}
|
|
||||||
enabled: true
|
|
||||||
EOF
|
|
||||||
lxd init --preseed < "$tmpfile"
|
|
||||||
rm "$tmpfile"
|
|
||||||
|
|
||||||
lxc config set core.https_address "[::]"
|
|
||||||
}
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# EXPERIMENTAL HELPERS
|
# EXPERIMENTAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue