From 7a23290ae4d69992ba301a38c4222153bc0ee109 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 24 Oct 2022 01:03:43 +0200 Subject: [PATCH] Implement _ynh_lxc_restart_container --- lib/ynh_lxd | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/ynh_lxd b/lib/ynh_lxd index 2c4233c..8485369 100644 --- a/lib/ynh_lxd +++ b/lib/ynh_lxd @@ -47,15 +47,26 @@ ynh_lxc_run_inside () { lxc exec $name -- /bin/bash -c "$command" } +# Restart a container +# +# usage: _ynh_lxc_restart_container --name=name +# | arg: -n, --name= - name of the LXC +# +# Requires YunoHost version *.*.* or higher. +_ynh_lxc_restart_container () { + # 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 "$@" + + ynh_lxc_stop --name=$name + lxc start "$name" +} _ynh_lxc_start_and_wait () { - restart_container() - { - ynh_lxc_stop --name=$1 - lxc start "$1" - } - # Try to start the container 3 times. local max_try=3 local i=0 @@ -75,7 +86,7 @@ _ynh_lxc_start_and_wait () { log_debug 'Failed to start the container ... restarting ...' failstart=1 - restart_container "$1" + _ynh_lxc_restart_container --name="$1" fi sleep 1s @@ -91,7 +102,7 @@ _ynh_lxc_start_and_wait () { log_debug 'Failed to access the internet ... restarting' failstart=1 - restart_container "$1" + _ynh_lxc_restart_container --name="$1" fi sleep 1s