implement ynh_lxc_run_inside

This commit is contained in:
yalh76 2022-10-24 00:37:14 +02:00
parent 3b085d60de
commit afe55f2b33
3 changed files with 23 additions and 8 deletions

View file

@ -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/

View file

@ -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"
}

View file

@ -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