diff --git a/lib/tests.sh b/lib/tests.sh index bcb8dec..ea3f03d 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -530,7 +530,7 @@ TEST_BACKUP_RESTORE () { # Remove the previous residual backups rm -rf $TEST_CONTEXT/ynh_backups - ynh_lxc_run_inside rm -rf /home/yunohost.backup/archives + ynh_lxc_run_inside --name=$LXC_NAME --command="rm -rf /home/yunohost.backup/archives" # BACKUP # Made a backup if the installation succeed @@ -573,7 +573,7 @@ TEST_BACKUP_RESTORE () { ynh_lxc_snapshot_load snap0 # Remove the previous residual backups - ynh_lxc_run_inside rm -rf /home/yunohost.backup/archives + ynh_lxc_run_inside --name=$LXC_NAME --command="rm -rf /home/yunohost.backup/archives" # Place the copy of the backup archive in the container. lxc file push -r $TEST_CONTEXT/ynh_backups/archives $LXC_NAME/home/yunohost.backup/ diff --git a/lib/ynh_lxd b/lib/ynh_lxd index 7bbb1f1..91b5783 100644 --- a/lib/ynh_lxd +++ b/lib/ynh_lxd @@ -17,8 +17,23 @@ ynh_lxc_stop () { } +# Run a command inside an LXC container +# +# usage: ynh_lxc_run_inside --name=name --command=command +# | arg: -n, --name= - name of the LXC +# | arg: -c, --command= - command to execute +# +# Requires YunoHost version *.*.* or higher. ynh_lxc_run_inside () { - lxc exec $LXC_NAME -- "$@" + # Declare an array to define the options of this helper. + local legacy_args=nc + local -A args_array=([n]=name= [c]=command=) + local name + local command + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + lxc exec $name -- /bin/bash -c "$command" } diff --git a/lib/ynh_lxd_package_check b/lib/ynh_lxd_package_check index 2445593..7b0e415 100644 --- a/lib/ynh_lxd_package_check +++ b/lib/ynh_lxd_package_check @@ -39,7 +39,7 @@ ynh_lxc_pc_exec () { ynh_lxc_pc_witness_file_create () { [ "$2" = "file" ] && local action="touch" || local action="mkdir -p" - ynh_lxc_run_inside $action $1 + ynh_lxc_run_inside --name=$LXC_NAME --command="$action $1" } ynh_lxc_pc_witness_files_set () { @@ -75,12 +75,12 @@ ynh_lxc_pc_witness_files_set () { ynh_lxc_pc_witness_file_create "/etc/systemd/system/witnessfile.service" file # Database - ynh_lxc_run_inside mysqladmin --wait status > /dev/null 2>&1 - echo "CREATE DATABASE witnessdb" | ynh_lxc_run_inside mysql --wait > /dev/null 2>&1 + ynh_lxc_run_inside --name=$LXC_NAME --command="mysqladmin --wait status > /dev/null 2>&1" + echo "CREATE DATABASE witnessdb" | ynh_lxc_run_inside --name=$LXC_NAME --command="mysql --wait > /dev/null 2>&1" } ynh_lxc_pc_witness_file_check () { - if ynh_lxc_run_inside test ! -e "$1" + if ynh_lxc_run_inside --name=$LXC_NAME --command="test ! -e \"$1\"" then log_error "The file $1 is missing ! Something gone wrong !" SET_RESULT "failure" witness @@ -119,7 +119,7 @@ ynh_lxc_pc_witness_files_check () { ynh_lxc_pc_witness_file_check "/etc/systemd/system/witnessfile.service" # Database - if ! ynh_lxc_run_inside mysqlshow witnessdb > /dev/null 2>&1 + if ! ynh_lxc_run_inside --name=$LXC_NAME --command="mysqlshow witnessdb > /dev/null 2>&1" then log_error "The database witnessdb is missing ! Something gone wrong !" SET_RESULT "failure" witness