forked from zaclys/searxng
LXC: separate lxc-suite from lxc & improved command line.
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
a258358633
commit
b1e90cff23
2
Makefile
2
Makefile
@ -110,7 +110,7 @@ test.sh:
|
||||
shellcheck -x utils/searx.sh
|
||||
shellcheck -x utils/morty.sh
|
||||
shellcheck -x utils/lxc.sh
|
||||
shellcheck -x utils/lxc.env
|
||||
shellcheck -x utils/lxc-searx.env
|
||||
shellcheck -x .config.sh
|
||||
|
||||
test.pep8: pyenvinstall
|
||||
|
@ -6,7 +6,7 @@
|
||||
# shellcheck source=utils/lib.sh
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||
source_dot_config
|
||||
source "${REPO_ROOT}/utils/lxc.env"
|
||||
source "${REPO_ROOT}/utils/lxc-searx.env"
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# config
|
||||
|
65
utils/lib.sh
65
utils/lib.sh
@ -1062,14 +1062,69 @@ EOF
|
||||
# containers
|
||||
# ----------
|
||||
|
||||
is_container() {
|
||||
sudo_or_exit
|
||||
|
||||
# usage: is_container && echo "process running inside a LXC container"
|
||||
# is_container || echo "process is not running inside a LXC container"
|
||||
in_container() {
|
||||
# Test if shell runs in a container.
|
||||
#
|
||||
# hint: Reads init process environment, therefore root access is required!
|
||||
#
|
||||
# usage: in_container && echo "process running inside a LXC container"
|
||||
# in_container || echo "process is not running inside a LXC container"
|
||||
#
|
||||
|
||||
sudo_or_exit
|
||||
# to be safe, take a look at the environment of process 1 (/sbin/init)
|
||||
grep -qa 'container=lxc' /proc/1/environ
|
||||
}
|
||||
|
||||
|
||||
lxc_exists(){
|
||||
|
||||
# usage: lxc_exists <name> || echo "container <name> does not exists"
|
||||
|
||||
lxc info "$1" &>/dev/null
|
||||
}
|
||||
|
||||
lxc_image_exists(){
|
||||
# usage: lxc_image_exists <alias> || echo "image <alias> does locally not exists"
|
||||
|
||||
lxc image info "local:$1" &>/dev/null
|
||||
|
||||
}
|
||||
|
||||
lxc_delete_container() {
|
||||
|
||||
# usage: lxc_delete_container <container-name>
|
||||
|
||||
if lxc info "$1" &>/dev/null; then
|
||||
info_msg "stop & delete instance ${_BBlue}${1}${_creset}"
|
||||
lxc stop "$1" &>/dev/null
|
||||
lxc delete "$1" | prefix_stdout
|
||||
else
|
||||
warn_msg "instance '$1' does not exist / can't delete :o"
|
||||
fi
|
||||
}
|
||||
|
||||
lxc_delete_local_image() {
|
||||
|
||||
# usage: lxc_delete_local_image <container-name>
|
||||
|
||||
info_msg "delete image 'local:$i'"
|
||||
lxc image delete "local:$i"
|
||||
}
|
||||
|
||||
|
||||
# IP
|
||||
# --
|
||||
|
||||
global_IPs(){
|
||||
# usage: global_IPS
|
||||
#
|
||||
# print list of host's SCOPE global addresses and adapters e.g::
|
||||
#
|
||||
# $ global_IPs
|
||||
# enp4s0|192.168.1.127
|
||||
# lxdbr0|10.246.86.1
|
||||
# lxdbr0|fd42:8c58:2cd:b73f::1
|
||||
|
||||
ip -o addr show | sed -nr 's/[0-9]*:\s*([a-z0-9]*).*inet[6]?\s*([a-z0-9.:]*).*scope global.*/\1|\2/p'
|
||||
}
|
||||
|
62
utils/lxc-searx.env
Normal file
62
utils/lxc-searx.env
Normal file
@ -0,0 +1,62 @@
|
||||
# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# shellcheck shell=bash
|
||||
|
||||
# This file is a setup of a LXC suite. It is sourced from different context, do
|
||||
# not manipulate the environment directly, implement functions and manipulate
|
||||
# environment only is subshells!
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# config
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
lxc_set_suite_env() {
|
||||
# name of https://images.linuxcontainers.org
|
||||
export LINUXCONTAINERS_ORG_NAME="${LINUXCONTAINERS_ORG_NAME:-images}"
|
||||
export LXC_HOST_PREFIX="${LXC_HOST_PREFIX:-searx}"
|
||||
export LXC_SUITE=(
|
||||
# end of standard support see https://wiki.ubuntu.com/Releases
|
||||
"$LINUXCONTAINERS_ORG_NAME:ubuntu/16.04" "ubu1604" # April 2021
|
||||
"$LINUXCONTAINERS_ORG_NAME:ubuntu/18.04" "ubu1804" # April 2023
|
||||
"$LINUXCONTAINERS_ORG_NAME:ubuntu/19.10" "ubu1910" # July 2020
|
||||
"$LINUXCONTAINERS_ORG_NAME:ubuntu/20.04" "ubu2004" # future (EOL 2030)
|
||||
|
||||
# EOL see https://fedoraproject.org/wiki/Releases
|
||||
"$LINUXCONTAINERS_ORG_NAME:fedora/31" "fedora31"
|
||||
|
||||
# rolling releases see https://www.archlinux.org/releng/releases/
|
||||
"$LINUXCONTAINERS_ORG_NAME:archlinux" "archlinux"
|
||||
)
|
||||
export FILTRON_API="0.0.0.0:4005"
|
||||
export FILTRON_LISTEN="0.0.0.0:4004"
|
||||
export MORTY_LISTEN="0.0.0.0:3000"
|
||||
}
|
||||
|
||||
lxc_suite_install() {
|
||||
(
|
||||
lxc_set_suite_env
|
||||
export FORCE_TIMEOUT=0
|
||||
"${LXC_REPO_ROOT}/utils/searx.sh" install all
|
||||
"${LXC_REPO_ROOT}/utils/morty.sh" install all
|
||||
"${LXC_REPO_ROOT}/utils/filtron.sh" install all
|
||||
|
||||
rst_title "suite installation finished ($(hostname))" part
|
||||
lxc_suite_info
|
||||
echo
|
||||
)
|
||||
}
|
||||
|
||||
lxc_suite_info() {
|
||||
(
|
||||
lxc_set_suite_env
|
||||
for ip in $(global_IPs) ; do
|
||||
if [[ $ip =~ .*:.* ]]; then
|
||||
info_msg "(${ip%|*}) IPv6: http://[${ip#*|}]"
|
||||
else
|
||||
# IPv4:
|
||||
info_msg "(${ip%|*}) filtron: http://${ip#*|}:4004/"
|
||||
info_msg "(${ip%|*}) morty: http://${ip#*|}:3000/"
|
||||
fi
|
||||
done
|
||||
)
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
# Herein we place all, what is needed to know when inside containers. Its
|
||||
# sourced from different context --> do not manipulate the environment directly,
|
||||
# implement functions!
|
||||
|
||||
# shellcheck shell=sh
|
||||
|
||||
searx_suite_set_env() {
|
||||
export FILTRON_API="0.0.0.0:4005"
|
||||
export FILTRON_LISTEN="0.0.0.0:4004"
|
||||
export MORTY_LISTEN="0.0.0.0:3000"
|
||||
}
|
367
utils/lxc.sh
367
utils/lxc.sh
@ -5,7 +5,11 @@
|
||||
# shellcheck source=utils/lib.sh
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||
source_dot_config
|
||||
source "${REPO_ROOT}/utils/lxc.env"
|
||||
|
||||
# load environment of the LXC suite
|
||||
LXC_ENV="${LXC_ENV:-${REPO_ROOT}/utils/lxc-searx.env}"
|
||||
source "$LXC_ENV"
|
||||
lxc_set_suite_env
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# config
|
||||
@ -14,33 +18,27 @@ source "${REPO_ROOT}/utils/lxc.env"
|
||||
# read also:
|
||||
# - https://lxd.readthedocs.io/en/latest/
|
||||
|
||||
# name of https://images.linuxcontainers.org
|
||||
LINUXCONTAINERS_ORG_NAME="${LINUXCONTAINERS_ORG_NAME:-images}"
|
||||
HOST_PREFIX="${HOST_PREFIX:-searx}"
|
||||
LXC_HOST_PREFIX="${LXC_HOST_PREFIX:-test}"
|
||||
|
||||
# where all folders from HOST are mounted
|
||||
LXC_SHARE_FOLDER="/share"
|
||||
LXC_REPO_ROOT="${LXC_SHARE_FOLDER}/$(basename "${REPO_ROOT}")"
|
||||
|
||||
TEST_IMAGES=(
|
||||
"$LINUXCONTAINERS_ORG_NAME:ubuntu/18.04" "ubu1804"
|
||||
"$LINUXCONTAINERS_ORG_NAME:ubuntu/19.04" "ubu1904"
|
||||
"$LINUXCONTAINERS_ORG_NAME:ubuntu/19.10" "ubu1910"
|
||||
"$LINUXCONTAINERS_ORG_NAME:ubuntu/20.04" "ubu2004"
|
||||
"$LINUXCONTAINERS_ORG_NAME:archlinux" "archlinux"
|
||||
"$LINUXCONTAINERS_ORG_NAME:fedora/31" "fedora31"
|
||||
)
|
||||
|
||||
ubu1804_boilerplate="
|
||||
ubu1604_boilerplate="
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update -y
|
||||
apt-get upgrade -y
|
||||
apt-get install -y git curl wget
|
||||
"
|
||||
ubu1804_boilerplate="$ubu1604_boilerplate"
|
||||
ubu1904_boilerplate="$ubu1804_boilerplate"
|
||||
ubu1910_boilerplate="$ubu1904_boilerplate"
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
ubu2004_boilerplate="$ubu1910_boilerplate"
|
||||
ubu2004_boilerplate="
|
||||
$ubu1910_boilerplate
|
||||
echo 'Set disable_coredump false' >> /etc/sudo.conf
|
||||
"
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
archlinux_boilerplate="
|
||||
@ -57,11 +55,13 @@ echo 'Set disable_coredump false' >> /etc/sudo.conf
|
||||
"
|
||||
|
||||
REMOTE_IMAGES=()
|
||||
CONTAINERS=()
|
||||
LOCAL_IMAGES=()
|
||||
|
||||
for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
|
||||
REMOTE_IMAGES=("${REMOTE_IMAGES[@]}" "${TEST_IMAGES[i]}")
|
||||
LOCAL_IMAGES=("${LOCAL_IMAGES[@]}" "${HOST_PREFIX}-${TEST_IMAGES[i+1]}")
|
||||
for ((i=0; i<${#LXC_SUITE[@]}; i+=2)); do
|
||||
REMOTE_IMAGES=("${REMOTE_IMAGES[@]}" "${LXC_SUITE[i]}")
|
||||
CONTAINERS=("${CONTAINERS[@]}" "${LXC_HOST_PREFIX}-${LXC_SUITE[i+1]}")
|
||||
LOCAL_IMAGES=("${LOCAL_IMAGES[@]}" "${LXC_SUITE[i+1]}")
|
||||
done
|
||||
|
||||
HOST_USER="${SUDO_USER:-$USER}"
|
||||
@ -71,36 +71,48 @@ HOST_GROUP_ID=$(id -g "${HOST_USER}")
|
||||
# ----------------------------------------------------------------------------
|
||||
usage() {
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
_cmd="$(basename "$0")"
|
||||
cat <<EOF
|
||||
|
||||
usage::
|
||||
|
||||
$(basename "$0") build [containers]
|
||||
$(basename "$0") install [searx-suite]
|
||||
$(basename "$0") remove [containers|subordinate]
|
||||
$(basename "$0") [start|stop] [containers|<container-name>]
|
||||
$(basename "$0") show [info|config|searx-suite]
|
||||
$(basename "$0") cmd ...
|
||||
$_cmd build [containers]
|
||||
$_cmd copy [images]
|
||||
$_cmd remove [containers|<name>|images|subordinate]
|
||||
$_cmd add [subordinate]
|
||||
$_cmd [start|stop] [containers|<name>]
|
||||
$_cmd show [info|config|suite|images]
|
||||
$_cmd cmd [--|<name>] ...
|
||||
$_cmd install [suite]
|
||||
|
||||
build / remove
|
||||
:containers: build & launch (or remove) all LXC containers
|
||||
build
|
||||
:containers: build & launch all LXC containers of the suite
|
||||
copy:
|
||||
:images: copy remote images of the suite into local storage
|
||||
remove
|
||||
:containers: delete all 'containers' or only <container-name>
|
||||
:images: delete local images of the suite
|
||||
add / remove
|
||||
:subordinate: lxd permission to map ${HOST_USER}'s user/group id through
|
||||
:subordinate: LXD permission to map ${HOST_USER}'s user/group id through
|
||||
start/stop
|
||||
:containers: start/stop of all 'containers' or only <container-name>
|
||||
:containers: start/stop all 'containers' from the suite
|
||||
:<name>: start/stop conatiner <name> from suite
|
||||
show
|
||||
:info: show info of all containers
|
||||
:config: show config of all containers
|
||||
:searx-suite: show searx-suite services of all containers
|
||||
cmd ...
|
||||
run commandline ... in all containers
|
||||
:info: show info of all the containers from LXC suite
|
||||
:config: show config of all the containers from the LXC suite
|
||||
:suite: show services of all the containers from the LXC suite
|
||||
:images: show information of local images
|
||||
cmd
|
||||
-- run command ... in all containers of the LXC suite
|
||||
:<name>: run command ... in container <name>
|
||||
install
|
||||
:searx-suite: install searx suite, includes morty & filtron
|
||||
:suite: install LXC suite, includes morty & filtron
|
||||
|
||||
all LXC containers:
|
||||
${LOCAL_IMAGES[@]}
|
||||
Images of the LXC suite:
|
||||
$(echo " ${LOCAL_IMAGES[*]}" | $FMT)
|
||||
|
||||
Containers of the LXC suite:
|
||||
$(echo " ${CONTAINERS[*]}" | $FMT)
|
||||
EOF
|
||||
[ -n "${1+x}" ] && err_msg "$1"
|
||||
}
|
||||
@ -122,10 +134,12 @@ main() {
|
||||
local exit_val
|
||||
local _usage="unknown or missing $1 command $2"
|
||||
|
||||
if [[ ! $1 == __* ]] && ! required_commands lxc; then
|
||||
lxd_info
|
||||
exit 42
|
||||
# don't check prerequisite when in recursion
|
||||
if [[ ! $1 == __* ]]; then
|
||||
! required_commands lxc && lxd_info && exit 42
|
||||
[[ -z $LXC_SUITE ]] && err_msg "missing LXC_SUITE" && exit 42
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
--source-only) ;;
|
||||
-h|--help) usage; exit 0;;
|
||||
@ -133,16 +147,28 @@ main() {
|
||||
build)
|
||||
sudo_or_exit
|
||||
case $2 in
|
||||
containers) build_instances ;;
|
||||
''|containers) build_instances ;;
|
||||
*) usage "$_usage"; exit 42;;
|
||||
esac
|
||||
;;
|
||||
copy)
|
||||
case $2 in
|
||||
''|images) lxc_copy_images_localy;;
|
||||
*) usage "$_usage"; exit 42;;
|
||||
esac
|
||||
;;
|
||||
remove)
|
||||
sudo_or_exit
|
||||
case $2 in
|
||||
containers) remove_instances ;;
|
||||
''|containers) remove_instances ;;
|
||||
images) lxc_delete_images_localy ;;
|
||||
subordinate) echo; del_subordinate_ids ;;
|
||||
*) usage "$_usage"; exit 42;;
|
||||
${LXC_HOST_PREFIX}-*)
|
||||
if ask_yn "Do you really want to delete conatiner $2"; then
|
||||
lxc_delete_container "$2"
|
||||
fi
|
||||
;;
|
||||
*) usage "unknown (or mising) container <name> $2"; exit 42;;
|
||||
esac
|
||||
;;
|
||||
add)
|
||||
@ -155,116 +181,86 @@ main() {
|
||||
start|stop)
|
||||
sudo_or_exit
|
||||
case $2 in
|
||||
containers) lxc_cmd "$1" ;;
|
||||
*)
|
||||
''|containers) lxc_cmd "$1" ;;
|
||||
${LXC_HOST_PREFIX}-*)
|
||||
info_msg "lxc $1 $2"
|
||||
lxc "$1" "$2" | prefix_stdout "[${_BBlue}${i}${_creset}] "
|
||||
;;
|
||||
*) usage "ukknown or missing container <name> $2"; exit 42;;
|
||||
esac
|
||||
;;
|
||||
show)
|
||||
sudo_or_exit
|
||||
case $2 in
|
||||
config) lxc_cmd config show;;
|
||||
info) lxc_cmd info;;
|
||||
searx-suite)
|
||||
for i in "${LOCAL_IMAGES[@]}"; do
|
||||
info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${LXC_REPO_ROOT}/utils/lxc.sh install $2${_creset}"
|
||||
lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __show "$2" | prefix_stdout "[${i}] "
|
||||
done
|
||||
suite) show_suite ;;
|
||||
images) show_images ;;
|
||||
config)
|
||||
rst_title "container configurations"
|
||||
echo
|
||||
lxc list "$LXC_HOST_PREFIX-"
|
||||
echo
|
||||
lxc_cmd config show
|
||||
;;
|
||||
info)
|
||||
rst_title "container info"
|
||||
echo
|
||||
lxc_cmd info
|
||||
;;
|
||||
*) usage "$_usage"; exit 42;;
|
||||
esac
|
||||
;;
|
||||
__show)
|
||||
case $2 in
|
||||
searx-suite) searx_suite_info ;;
|
||||
suite) lxc_suite_info ;;
|
||||
esac
|
||||
;;
|
||||
cmd)
|
||||
sudo_or_exit
|
||||
shift
|
||||
for i in "${LOCAL_IMAGES[@]}"; do
|
||||
exit_val=
|
||||
info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${*}${_creset}"
|
||||
lxc exec "${i}" -- "$@"
|
||||
exit_val=$?
|
||||
if [[ $exit_val -ne 0 ]]; then
|
||||
warn_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
|
||||
else
|
||||
info_msg "[${_BBlue}${i}${_creset}] exit code (${exit_val}) from ${_BGreen}${*}${_creset}"
|
||||
fi
|
||||
echo
|
||||
done
|
||||
case $1 in
|
||||
--)
|
||||
shift
|
||||
for name in "${CONTAINERS[@]}"; do
|
||||
lxc_exec_cmd "${name}" "$@"
|
||||
done
|
||||
;;
|
||||
${LXC_HOST_PREFIX}-*)
|
||||
local name=$1
|
||||
shift
|
||||
lxc_exec_cmd "${name}" "$@"
|
||||
;;
|
||||
|
||||
*) usage "unknown <name>: $1"; exit 42
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
install)
|
||||
sudo_or_exit
|
||||
case $2 in
|
||||
searx-suite)
|
||||
for i in "${LOCAL_IMAGES[@]}"; do
|
||||
info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${LXC_REPO_ROOT}/utils/lxc.sh install $2${_creset}"
|
||||
lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2" | prefix_stdout "[${i}] "
|
||||
done
|
||||
;;
|
||||
*) usage "$_usage"; exit 42;;
|
||||
suite) install_suite ;;
|
||||
*) usage "$_usage"; exit 42 ;;
|
||||
esac
|
||||
;;
|
||||
__install)
|
||||
case $2 in
|
||||
searx-suite) searx_suite_install ;;
|
||||
suite) lxc_suite_install ;;
|
||||
esac
|
||||
;;
|
||||
doc)
|
||||
echo
|
||||
echo ".. generic utils/lxc.sh documentation"
|
||||
;;
|
||||
|
||||
*)
|
||||
usage "unknown or missing command $1"; exit 42;;
|
||||
-*) usage "unknown option $1"; exit 42;;
|
||||
*) usage "unknown or missing command $1"; exit 42;;
|
||||
esac
|
||||
}
|
||||
|
||||
searx_suite_install() {
|
||||
(
|
||||
searx_suite_set_env
|
||||
export FORCE_TIMEOUT=0
|
||||
"${LXC_REPO_ROOT}/utils/searx.sh" install all
|
||||
"${LXC_REPO_ROOT}/utils/morty.sh" install all
|
||||
"${LXC_REPO_ROOT}/utils/filtron.sh" install all
|
||||
|
||||
rst_title "searx-suite installation finished ($(hostname))" part
|
||||
searx_suite_info
|
||||
echo
|
||||
)
|
||||
}
|
||||
|
||||
searx_suite_info() {
|
||||
(
|
||||
searx_suite_set_env
|
||||
rst_para "Services of the container $(hostname)"
|
||||
for ip in $(hostname -I); do
|
||||
echo
|
||||
if [[ $ip =~ .*:.* ]]; then
|
||||
:
|
||||
# IPv6: not yet implemented / tested
|
||||
# echo " searx (filtron) --> http://[$ip]:4004/"
|
||||
# echo " morty --> http://[$ip]:3000/"
|
||||
else
|
||||
# IPv4:
|
||||
echo " searx (filtron) --> http://$ip:4004/"
|
||||
echo " morty --> http://$ip:3000/"
|
||||
fi
|
||||
done
|
||||
)
|
||||
}
|
||||
|
||||
build_instances() {
|
||||
rst_title "Build LXC instances"
|
||||
|
||||
rst_title "copy images" section
|
||||
echo
|
||||
add_subordinate_ids
|
||||
lxc_copy_images_localy
|
||||
# lxc image list local: && wait_key
|
||||
echo
|
||||
rst_title "build containers" section
|
||||
echo
|
||||
@ -272,64 +268,141 @@ build_instances() {
|
||||
lxc_config_containers
|
||||
lxc_boilerplate_containers
|
||||
echo
|
||||
lxc list "$HOST_PREFIX"
|
||||
lxc list "$LXC_HOST_PREFIX"
|
||||
}
|
||||
|
||||
remove_instances() {
|
||||
rst_title "Remove LXC instances"
|
||||
lxc list "$HOST_PREFIX"
|
||||
echo -en "\\nLXC containers(s)::\\n\\n ${LOCAL_IMAGES[*]}\\n" | $FMT
|
||||
if ask_yn "Do you really want to delete all images"; then
|
||||
lxc_delete_containers
|
||||
rst_para "existing containers matching ${_BGreen}$LXC_HOST_PREFIX-*${_creset}"
|
||||
echo
|
||||
lxc list "$LXC_HOST_PREFIX-"
|
||||
echo -en "\\n${_BRed}LXC containers to delete::${_creset}\\n\\n ${CONTAINERS[*]}\\n" | $FMT
|
||||
if ask_yn "Do you really want to delete these conatiners"; then
|
||||
for i in "${CONTAINERS[@]}"; do
|
||||
lxc_delete_container "$i"
|
||||
done
|
||||
fi
|
||||
echo
|
||||
lxc list "$HOST_PREFIX"
|
||||
# lxc image list local: && wait_key
|
||||
lxc list "$LXC_HOST_PREFIX-"
|
||||
}
|
||||
|
||||
# images
|
||||
# ------
|
||||
|
||||
lxc_copy_images_localy() {
|
||||
for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
|
||||
if lxc image info "local:${TEST_IMAGES[i+1]}" &>/dev/null; then
|
||||
info_msg "image ${TEST_IMAGES[i]} already copied --> ${TEST_IMAGES[i+1]}"
|
||||
rst_title "copy images" section
|
||||
echo
|
||||
for ((i=0; i<${#LXC_SUITE[@]}; i+=2)); do
|
||||
if lxc_image_exists "local:${LXC_SUITE[i+1]}"; then
|
||||
info_msg "image ${LXC_SUITE[i]} already copied --> ${LXC_SUITE[i+1]}"
|
||||
else
|
||||
info_msg "copy image locally ${TEST_IMAGES[i]} --> ${TEST_IMAGES[i+1]}"
|
||||
lxc image copy "${TEST_IMAGES[i]}" local: \
|
||||
--alias "${TEST_IMAGES[i+1]}" | prefix_stdout
|
||||
info_msg "copy image locally ${LXC_SUITE[i]} --> ${LXC_SUITE[i+1]}"
|
||||
lxc image copy "${LXC_SUITE[i]}" local: \
|
||||
--alias "${LXC_SUITE[i+1]}" | prefix_stdout
|
||||
fi
|
||||
done
|
||||
# lxc image list local: && wait_key
|
||||
}
|
||||
|
||||
lxc_delete_images_localy() {
|
||||
rst_title "Delete LXC images"
|
||||
rst_para "local existing images"
|
||||
echo
|
||||
for i in "${LOCAL_IMAGES[@]}"; do
|
||||
info_msg "delete image 'local:$i'"
|
||||
lxc image delete "local:$i"
|
||||
done
|
||||
#lxc image list local:
|
||||
lxc image list local:
|
||||
echo -en "\\n${_BRed}LXC images to delete::${_creset}\\n\\n ${LOCAL_IMAGES[*]}\\n"
|
||||
if ask_yn "Do you really want to delete these images"; then
|
||||
for i in "${LOCAL_IMAGES[@]}"; do
|
||||
lxc_delete_local_image "$i"
|
||||
done
|
||||
fi
|
||||
echo
|
||||
lxc image list local:
|
||||
}
|
||||
|
||||
show_images(){
|
||||
rst_title "local images"
|
||||
echo
|
||||
lxc image list local:
|
||||
echo -en "\\n${_Green}LXC suite images::${_creset}\\n\\n ${LOCAL_IMAGES[*]}\\n"
|
||||
wait_key
|
||||
for i in "${LOCAL_IMAGES[@]}"; do
|
||||
if lxc_image_exists "$i"; then
|
||||
info_msg "lxc image info ${_BBlue}${i}${_creset}"
|
||||
lxc image info "$i" | prefix_stdout "[${_BBlue}${i}${_creset}] "
|
||||
else
|
||||
warn_msg "image ${_BBlue}$i${_creset} does not yet exists"
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
|
||||
# container
|
||||
# ---------
|
||||
|
||||
lxc_cmd() {
|
||||
for i in "${LOCAL_IMAGES[@]}"; do
|
||||
info_msg "lxc $* $i"
|
||||
lxc "$@" "$i" | prefix_stdout "[${_BBlue}${i}${_creset}] "
|
||||
show_suite(){
|
||||
rst_title "LXC suite ($LXC_HOST_PREFIX-*)"
|
||||
echo
|
||||
lxc list "$LXC_HOST_PREFIX-"
|
||||
echo
|
||||
for i in "${CONTAINERS[@]}"; do
|
||||
if ! lxc_exists "$i"; then
|
||||
warn_msg "container ${_BBlue}$i${_creset} does not yet exists"
|
||||
else
|
||||
lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __show suite \
|
||||
| prefix_stdout "[${_BBlue}${i}${_creset}] "
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
install_suite() {
|
||||
for i in "${CONTAINERS[@]}"; do
|
||||
if ! lxc_exists "$i"; then
|
||||
warn_msg "container ${_BBlue}$i${_creset} does not yet exists"
|
||||
else
|
||||
info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${LXC_REPO_ROOT}/utils/lxc.sh install suite${_creset}"
|
||||
lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __install suite \
|
||||
| prefix_stdout "[${_BBlue}${i}${_creset}] "
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
lxc_cmd() {
|
||||
for i in "${CONTAINERS[@]}"; do
|
||||
if ! lxc_exists "$i"; then
|
||||
warn_msg "container ${_BBlue}$i${_creset} does not yet exists"
|
||||
else
|
||||
info_msg "lxc $* $i"
|
||||
lxc "$@" "$i" | prefix_stdout "[${_BBlue}${i}${_creset}] "
|
||||
echo
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
lxc_exec_cmd() {
|
||||
local name="$1"
|
||||
shift
|
||||
exit_val=
|
||||
info_msg "[${_BBlue}${name}${_creset}] ${_BGreen}${*}${_creset}"
|
||||
lxc exec "${name}" -- "$@"
|
||||
exit_val=$?
|
||||
if [[ $exit_val -ne 0 ]]; then
|
||||
warn_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
|
||||
else
|
||||
info_msg "[${_BBlue}${i}${_creset}] exit code (${exit_val}) from ${_BGreen}${*}${_creset}"
|
||||
fi
|
||||
echo
|
||||
}
|
||||
|
||||
lxc_init_containers() {
|
||||
|
||||
local image_name
|
||||
local container_name
|
||||
|
||||
for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
|
||||
for ((i=0; i<${#LXC_SUITE[@]}; i+=2)); do
|
||||
|
||||
image_name="${TEST_IMAGES[i+1]}"
|
||||
container_name="${HOST_PREFIX}-${image_name}"
|
||||
image_name="${LXC_SUITE[i+1]}"
|
||||
container_name="${LXC_HOST_PREFIX}-${image_name}"
|
||||
|
||||
if lxc info "${container_name}" &>/dev/null; then
|
||||
info_msg "container '${container_name}' already exists"
|
||||
@ -341,7 +414,7 @@ lxc_init_containers() {
|
||||
}
|
||||
|
||||
lxc_config_containers() {
|
||||
for i in "${LOCAL_IMAGES[@]}"; do
|
||||
for i in "${CONTAINERS[@]}"; do
|
||||
info_msg "[${_BBlue}${i}${_creset}] configure container ..."
|
||||
|
||||
info_msg "[${_BBlue}${i}${_creset}] map uid/gid from host to container"
|
||||
@ -364,10 +437,10 @@ lxc_boilerplate_containers() {
|
||||
local container_name
|
||||
local boilerplate_script
|
||||
|
||||
for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
|
||||
for ((i=0; i<${#LXC_SUITE[@]}; i+=2)); do
|
||||
|
||||
image_name="${TEST_IMAGES[i+1]}"
|
||||
container_name="${HOST_PREFIX}-${image_name}"
|
||||
image_name="${LXC_SUITE[i+1]}"
|
||||
container_name="${LXC_HOST_PREFIX}-${image_name}"
|
||||
boilerplate_script="${image_name}_boilerplate"
|
||||
boilerplate_script="${!boilerplate_script}"
|
||||
|
||||
@ -386,18 +459,6 @@ lxc_boilerplate_containers() {
|
||||
done
|
||||
}
|
||||
|
||||
lxc_delete_containers() {
|
||||
for i in "${LOCAL_IMAGES[@]}"; do
|
||||
if lxc info "$i" &>/dev/null; then
|
||||
info_msg "stop & delete instance ${_BBlue}${i}${_creset}"
|
||||
lxc stop "$i" &>/dev/null
|
||||
lxc delete "$i" | prefix_stdout
|
||||
else
|
||||
warn_msg "instance '$i' does not exist / can't delete :o"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# subordinates
|
||||
# ------------
|
||||
#
|
||||
|
@ -5,7 +5,7 @@
|
||||
# shellcheck source=utils/lib.sh
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||
source_dot_config
|
||||
source "${REPO_ROOT}/utils/lxc.env"
|
||||
source "${REPO_ROOT}/utils/lxc-searx.env"
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# config
|
||||
|
@ -6,7 +6,7 @@
|
||||
# shellcheck source=utils/lib.sh
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||
source_dot_config
|
||||
source "${REPO_ROOT}/utils/lxc.env"
|
||||
source "${REPO_ROOT}/utils/lxc-searx.env"
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# config
|
||||
@ -544,13 +544,13 @@ EOF
|
||||
uWSGI_app_available "$SEARX_UWSGI_APP" \
|
||||
|| err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
|
||||
|
||||
if is_container; then
|
||||
if in_container; then
|
||||
warn_msg "runnning inside container ..."
|
||||
for ip in $(hostname -I); do
|
||||
for ip in $(global_IPs); do
|
||||
if [[ $ip =~ .*:.* ]]; then
|
||||
info_msg " public HTTP service (IPv6) --> http://[$ip]"
|
||||
info_msg " public HTTP service (IPv6) --> http://${ip#*|}"
|
||||
else
|
||||
info_msg " public HTTP service (IPv4) --> http://$ip"
|
||||
info_msg " public HTTP service (IPv4) --> http://${ip#*|}"
|
||||
fi
|
||||
done
|
||||
warn_msg "SEARX_INTERNAL_URL not available from outside"
|
||||
@ -564,7 +564,7 @@ EOF
|
||||
|
||||
if ! service_is_available "${PUBLIC_URL}"; then
|
||||
warn_msg "Public service at ${PUBLIC_URL} is not available!"
|
||||
if is_container; then
|
||||
if in_container; then
|
||||
warn_msg "Check if public name is correct and routed or use the public IP from above."
|
||||
fi
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user