mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
implement ynh_lxc_run_inside
This commit is contained in:
parent
3b085d60de
commit
afe55f2b33
3 changed files with 23 additions and 8 deletions
|
@ -530,7 +530,7 @@ TEST_BACKUP_RESTORE () {
|
||||||
|
|
||||||
# Remove the previous residual backups
|
# Remove the previous residual backups
|
||||||
rm -rf $TEST_CONTEXT/ynh_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
|
# BACKUP
|
||||||
# Made a backup if the installation succeed
|
# Made a backup if the installation succeed
|
||||||
|
@ -573,7 +573,7 @@ TEST_BACKUP_RESTORE () {
|
||||||
ynh_lxc_snapshot_load snap0
|
ynh_lxc_snapshot_load snap0
|
||||||
|
|
||||||
# Remove the previous residual backups
|
# 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.
|
# Place the copy of the backup archive in the container.
|
||||||
lxc file push -r $TEST_CONTEXT/ynh_backups/archives $LXC_NAME/home/yunohost.backup/
|
lxc file push -r $TEST_CONTEXT/ynh_backups/archives $LXC_NAME/home/yunohost.backup/
|
||||||
|
|
17
lib/ynh_lxd
17
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 () {
|
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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ ynh_lxc_pc_exec () {
|
||||||
|
|
||||||
ynh_lxc_pc_witness_file_create () {
|
ynh_lxc_pc_witness_file_create () {
|
||||||
[ "$2" = "file" ] && local action="touch" || local action="mkdir -p"
|
[ "$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 () {
|
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
|
ynh_lxc_pc_witness_file_create "/etc/systemd/system/witnessfile.service" file
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
ynh_lxc_run_inside mysqladmin --wait status > /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 mysql --wait > /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 () {
|
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
|
then
|
||||||
log_error "The file $1 is missing ! Something gone wrong !"
|
log_error "The file $1 is missing ! Something gone wrong !"
|
||||||
SET_RESULT "failure" witness
|
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"
|
ynh_lxc_pc_witness_file_check "/etc/systemd/system/witnessfile.service"
|
||||||
|
|
||||||
# Database
|
# 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
|
then
|
||||||
log_error "The database witnessdb is missing ! Something gone wrong !"
|
log_error "The database witnessdb is missing ! Something gone wrong !"
|
||||||
SET_RESULT "failure" witness
|
SET_RESULT "failure" witness
|
||||||
|
|
Loading…
Add table
Reference in a new issue