mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
Implement ynh_lxc_swapfiles_clean
This commit is contained in:
parent
ebbbc5b419
commit
d3883f6b69
2 changed files with 21 additions and 8 deletions
27
lib/ynh_lxd
27
lib/ynh_lxd
|
@ -138,14 +138,27 @@ _ynh_lxc_start_and_wait () {
|
||||||
LXC_IP=$(lxc exec $name -- hostname -I | cut -d' ' -f1 | grep -E -o "\<[0-9.]{8,}\>")
|
LXC_IP=$(lxc exec $name -- hostname -I | cut -d' ' -f1 | grep -E -o "\<[0-9.]{8,}\>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Clean the swapfiles of an LXC container
|
||||||
|
#
|
||||||
|
# usage: ynh_lxc_swapfiles_clean --name=name
|
||||||
|
# | arg: -n, --name= - name of the LXC
|
||||||
|
#
|
||||||
|
# Requires YunoHost version *.*.* or higher.
|
||||||
ynh_lxc_swapfiles_clean () {
|
ynh_lxc_swapfiles_clean () {
|
||||||
|
# Declare an array to define the options of this helper.
|
||||||
|
local legacy_args=n
|
||||||
|
local -A args_array=([n]=name=)
|
||||||
|
local name
|
||||||
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
# Restart it if needed
|
# Restart it if needed
|
||||||
if [ "$(lxc info $LXC_NAME | grep Status | awk '{print tolower($2)}')" != "running" ]; then
|
if [ "$(lxc info $name | grep Status | awk '{print tolower($2)}')" != "running" ]; then
|
||||||
lxc start $LXC_NAME
|
lxc start $name
|
||||||
_ynh_lxc_start_and_wait --name=$LXC_NAME
|
_ynh_lxc_start_and_wait --name=$name
|
||||||
fi
|
fi
|
||||||
lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do swapoff $swapfile; done'
|
lxc exec $name -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do swapoff $swapfile; done'
|
||||||
lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do rm -f $swapfile; done'
|
lxc exec $name -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do rm -f $swapfile; done'
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_lxc_snapshot_exists () {
|
ynh_lxc_snapshot_exists () {
|
||||||
|
@ -161,7 +174,7 @@ ynh_lxc_snapshot_load () {
|
||||||
log_debug "Loading snapshot $snapname ..."
|
log_debug "Loading snapshot $snapname ..."
|
||||||
|
|
||||||
# Remove swap files before restoring the snapshot.
|
# Remove swap files before restoring the snapshot.
|
||||||
ynh_lxc_swapfiles_clean
|
ynh_lxc_swapfiles_clean --name=$LXC_NAME
|
||||||
|
|
||||||
ynh_lxc_stop --name=$LXC_NAME
|
ynh_lxc_stop --name=$LXC_NAME
|
||||||
|
|
||||||
|
@ -174,7 +187,7 @@ ynh_lxc_reset () {
|
||||||
# If the container exists
|
# If the container exists
|
||||||
if lxc info $LXC_NAME >/dev/null 2>/dev/null; then
|
if lxc info $LXC_NAME >/dev/null 2>/dev/null; then
|
||||||
# Remove swap files before deletting the continer
|
# Remove swap files before deletting the continer
|
||||||
ynh_lxc_swapfiles_clean
|
ynh_lxc_swapfiles_clean --name=$LXC_NAME
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_lxc_stop --name=$LXC_NAME
|
ynh_lxc_stop --name=$LXC_NAME
|
||||||
|
|
|
@ -255,7 +255,7 @@ ynh_lxc_pc_snapshot_create () {
|
||||||
ynh_lxc_pc_witness_files_check --name=$name >&2
|
ynh_lxc_pc_witness_files_check --name=$name >&2
|
||||||
|
|
||||||
# Remove swap files to avoid killing the CI with huge snapshots.
|
# Remove swap files to avoid killing the CI with huge snapshots.
|
||||||
ynh_lxc_swapfiles_clean
|
ynh_lxc_swapfiles_clean --name=$name
|
||||||
|
|
||||||
ynh_lxc_stop --name=$name
|
ynh_lxc_stop --name=$name
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue