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/searx.sh
|
||||||
shellcheck -x utils/morty.sh
|
shellcheck -x utils/morty.sh
|
||||||
shellcheck -x utils/lxc.sh
|
shellcheck -x utils/lxc.sh
|
||||||
shellcheck -x utils/lxc.env
|
shellcheck -x utils/lxc-searx.env
|
||||||
shellcheck -x .config.sh
|
shellcheck -x .config.sh
|
||||||
|
|
||||||
test.pep8: pyenvinstall
|
test.pep8: pyenvinstall
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# shellcheck source=utils/lib.sh
|
# shellcheck source=utils/lib.sh
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||||
source_dot_config
|
source_dot_config
|
||||||
source "${REPO_ROOT}/utils/lxc.env"
|
source "${REPO_ROOT}/utils/lxc-searx.env"
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# config
|
# config
|
||||||
|
|
65
utils/lib.sh
65
utils/lib.sh
|
@ -1062,14 +1062,69 @@ EOF
|
||||||
# containers
|
# containers
|
||||||
# ----------
|
# ----------
|
||||||
|
|
||||||
is_container() {
|
in_container() {
|
||||||
sudo_or_exit
|
# Test if shell runs in a container.
|
||||||
|
|
||||||
# usage: is_container && echo "process running inside a LXC container"
|
|
||||||
# is_container || echo "process is not running inside a LXC container"
|
|
||||||
#
|
#
|
||||||
# hint: Reads init process environment, therefore root access is required!
|
# 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)
|
# to be safe, take a look at the environment of process 1 (/sbin/init)
|
||||||
grep -qa 'container=lxc' /proc/1/environ
|
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'
|
||||||
|
}
|
||||||
|
|
|
@ -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"
|
|
||||||
}
|
|
353
utils/lxc.sh
353
utils/lxc.sh
|
@ -5,7 +5,11 @@
|
||||||
# shellcheck source=utils/lib.sh
|
# shellcheck source=utils/lib.sh
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||||
source_dot_config
|
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
|
# config
|
||||||
|
@ -14,33 +18,27 @@ source "${REPO_ROOT}/utils/lxc.env"
|
||||||
# read also:
|
# read also:
|
||||||
# - https://lxd.readthedocs.io/en/latest/
|
# - https://lxd.readthedocs.io/en/latest/
|
||||||
|
|
||||||
# name of https://images.linuxcontainers.org
|
LXC_HOST_PREFIX="${LXC_HOST_PREFIX:-test}"
|
||||||
LINUXCONTAINERS_ORG_NAME="${LINUXCONTAINERS_ORG_NAME:-images}"
|
|
||||||
HOST_PREFIX="${HOST_PREFIX:-searx}"
|
|
||||||
|
|
||||||
# where all folders from HOST are mounted
|
# where all folders from HOST are mounted
|
||||||
LXC_SHARE_FOLDER="/share"
|
LXC_SHARE_FOLDER="/share"
|
||||||
LXC_REPO_ROOT="${LXC_SHARE_FOLDER}/$(basename "${REPO_ROOT}")"
|
LXC_REPO_ROOT="${LXC_SHARE_FOLDER}/$(basename "${REPO_ROOT}")"
|
||||||
|
|
||||||
TEST_IMAGES=(
|
ubu1604_boilerplate="
|
||||||
"$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="
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
apt-get update -y
|
apt-get update -y
|
||||||
apt-get upgrade -y
|
apt-get upgrade -y
|
||||||
apt-get install -y git curl wget
|
apt-get install -y git curl wget
|
||||||
"
|
"
|
||||||
|
ubu1804_boilerplate="$ubu1604_boilerplate"
|
||||||
ubu1904_boilerplate="$ubu1804_boilerplate"
|
ubu1904_boilerplate="$ubu1804_boilerplate"
|
||||||
ubu1910_boilerplate="$ubu1904_boilerplate"
|
ubu1910_boilerplate="$ubu1904_boilerplate"
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
ubu2004_boilerplate="$ubu1910_boilerplate"
|
ubu2004_boilerplate="
|
||||||
|
$ubu1910_boilerplate
|
||||||
|
echo 'Set disable_coredump false' >> /etc/sudo.conf
|
||||||
|
"
|
||||||
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
archlinux_boilerplate="
|
archlinux_boilerplate="
|
||||||
|
@ -57,11 +55,13 @@ echo 'Set disable_coredump false' >> /etc/sudo.conf
|
||||||
"
|
"
|
||||||
|
|
||||||
REMOTE_IMAGES=()
|
REMOTE_IMAGES=()
|
||||||
|
CONTAINERS=()
|
||||||
LOCAL_IMAGES=()
|
LOCAL_IMAGES=()
|
||||||
|
|
||||||
for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
|
for ((i=0; i<${#LXC_SUITE[@]}; i+=2)); do
|
||||||
REMOTE_IMAGES=("${REMOTE_IMAGES[@]}" "${TEST_IMAGES[i]}")
|
REMOTE_IMAGES=("${REMOTE_IMAGES[@]}" "${LXC_SUITE[i]}")
|
||||||
LOCAL_IMAGES=("${LOCAL_IMAGES[@]}" "${HOST_PREFIX}-${TEST_IMAGES[i+1]}")
|
CONTAINERS=("${CONTAINERS[@]}" "${LXC_HOST_PREFIX}-${LXC_SUITE[i+1]}")
|
||||||
|
LOCAL_IMAGES=("${LOCAL_IMAGES[@]}" "${LXC_SUITE[i+1]}")
|
||||||
done
|
done
|
||||||
|
|
||||||
HOST_USER="${SUDO_USER:-$USER}"
|
HOST_USER="${SUDO_USER:-$USER}"
|
||||||
|
@ -71,36 +71,48 @@ HOST_GROUP_ID=$(id -g "${HOST_USER}")
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
usage() {
|
usage() {
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
_cmd="$(basename "$0")"
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
usage::
|
usage::
|
||||||
|
|
||||||
$(basename "$0") build [containers]
|
$_cmd build [containers]
|
||||||
$(basename "$0") install [searx-suite]
|
$_cmd copy [images]
|
||||||
$(basename "$0") remove [containers|subordinate]
|
$_cmd remove [containers|<name>|images|subordinate]
|
||||||
$(basename "$0") [start|stop] [containers|<container-name>]
|
$_cmd add [subordinate]
|
||||||
$(basename "$0") show [info|config|searx-suite]
|
$_cmd [start|stop] [containers|<name>]
|
||||||
$(basename "$0") cmd ...
|
$_cmd show [info|config|suite|images]
|
||||||
|
$_cmd cmd [--|<name>] ...
|
||||||
|
$_cmd install [suite]
|
||||||
|
|
||||||
build / remove
|
build
|
||||||
:containers: build & launch (or remove) all LXC containers
|
: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
|
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
|
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
|
show
|
||||||
:info: show info of all containers
|
:info: show info of all the containers from LXC suite
|
||||||
:config: show config of all containers
|
:config: show config of all the containers from the LXC suite
|
||||||
:searx-suite: show searx-suite services of all containers
|
:suite: show services of all the containers from the LXC suite
|
||||||
cmd ...
|
:images: show information of local images
|
||||||
run commandline ... in all containers
|
cmd
|
||||||
|
-- run command ... in all containers of the LXC suite
|
||||||
|
:<name>: run command ... in container <name>
|
||||||
install
|
install
|
||||||
:searx-suite: install searx suite, includes morty & filtron
|
:suite: install LXC suite, includes morty & filtron
|
||||||
|
|
||||||
all LXC containers:
|
Images of the LXC suite:
|
||||||
${LOCAL_IMAGES[@]}
|
$(echo " ${LOCAL_IMAGES[*]}" | $FMT)
|
||||||
|
|
||||||
|
Containers of the LXC suite:
|
||||||
|
$(echo " ${CONTAINERS[*]}" | $FMT)
|
||||||
EOF
|
EOF
|
||||||
[ -n "${1+x}" ] && err_msg "$1"
|
[ -n "${1+x}" ] && err_msg "$1"
|
||||||
}
|
}
|
||||||
|
@ -122,10 +134,12 @@ main() {
|
||||||
local exit_val
|
local exit_val
|
||||||
local _usage="unknown or missing $1 command $2"
|
local _usage="unknown or missing $1 command $2"
|
||||||
|
|
||||||
if [[ ! $1 == __* ]] && ! required_commands lxc; then
|
# don't check prerequisite when in recursion
|
||||||
lxd_info
|
if [[ ! $1 == __* ]]; then
|
||||||
exit 42
|
! required_commands lxc && lxd_info && exit 42
|
||||||
|
[[ -z $LXC_SUITE ]] && err_msg "missing LXC_SUITE" && exit 42
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
--source-only) ;;
|
--source-only) ;;
|
||||||
-h|--help) usage; exit 0;;
|
-h|--help) usage; exit 0;;
|
||||||
|
@ -133,16 +147,28 @@ main() {
|
||||||
build)
|
build)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
case $2 in
|
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;;
|
*) usage "$_usage"; exit 42;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
remove)
|
remove)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
case $2 in
|
case $2 in
|
||||||
containers) remove_instances ;;
|
''|containers) remove_instances ;;
|
||||||
|
images) lxc_delete_images_localy ;;
|
||||||
subordinate) echo; del_subordinate_ids ;;
|
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
|
esac
|
||||||
;;
|
;;
|
||||||
add)
|
add)
|
||||||
|
@ -155,116 +181,86 @@ main() {
|
||||||
start|stop)
|
start|stop)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
case $2 in
|
case $2 in
|
||||||
containers) lxc_cmd "$1" ;;
|
''|containers) lxc_cmd "$1" ;;
|
||||||
*)
|
${LXC_HOST_PREFIX}-*)
|
||||||
info_msg "lxc $1 $2"
|
info_msg "lxc $1 $2"
|
||||||
lxc "$1" "$2" | prefix_stdout "[${_BBlue}${i}${_creset}] "
|
lxc "$1" "$2" | prefix_stdout "[${_BBlue}${i}${_creset}] "
|
||||||
;;
|
;;
|
||||||
|
*) usage "ukknown or missing container <name> $2"; exit 42;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
show)
|
show)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
case $2 in
|
case $2 in
|
||||||
config) lxc_cmd config show;;
|
suite) show_suite ;;
|
||||||
info) lxc_cmd info;;
|
images) show_images ;;
|
||||||
searx-suite)
|
config)
|
||||||
for i in "${LOCAL_IMAGES[@]}"; do
|
rst_title "container configurations"
|
||||||
info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${LXC_REPO_ROOT}/utils/lxc.sh install $2${_creset}"
|
echo
|
||||||
lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __show "$2" | prefix_stdout "[${i}] "
|
lxc list "$LXC_HOST_PREFIX-"
|
||||||
done
|
echo
|
||||||
|
lxc_cmd config show
|
||||||
|
;;
|
||||||
|
info)
|
||||||
|
rst_title "container info"
|
||||||
|
echo
|
||||||
|
lxc_cmd info
|
||||||
;;
|
;;
|
||||||
*) usage "$_usage"; exit 42;;
|
*) usage "$_usage"; exit 42;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
__show)
|
__show)
|
||||||
case $2 in
|
case $2 in
|
||||||
searx-suite) searx_suite_info ;;
|
suite) lxc_suite_info ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
cmd)
|
cmd)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
shift
|
shift
|
||||||
for i in "${LOCAL_IMAGES[@]}"; do
|
case $1 in
|
||||||
exit_val=
|
--)
|
||||||
info_msg "[${_BBlue}${i}${_creset}] ${_BGreen}${*}${_creset}"
|
shift
|
||||||
lxc exec "${i}" -- "$@"
|
for name in "${CONTAINERS[@]}"; do
|
||||||
exit_val=$?
|
lxc_exec_cmd "${name}" "$@"
|
||||||
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
|
done
|
||||||
;;
|
;;
|
||||||
|
${LXC_HOST_PREFIX}-*)
|
||||||
|
local name=$1
|
||||||
|
shift
|
||||||
|
lxc_exec_cmd "${name}" "$@"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*) usage "unknown <name>: $1"; exit 42
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
install)
|
install)
|
||||||
sudo_or_exit
|
sudo_or_exit
|
||||||
case $2 in
|
case $2 in
|
||||||
searx-suite)
|
suite) install_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 ;;
|
*) usage "$_usage"; exit 42 ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
__install)
|
__install)
|
||||||
case $2 in
|
case $2 in
|
||||||
searx-suite) searx_suite_install ;;
|
suite) lxc_suite_install ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
doc)
|
doc)
|
||||||
echo
|
echo
|
||||||
echo ".. generic utils/lxc.sh documentation"
|
echo ".. generic utils/lxc.sh documentation"
|
||||||
;;
|
;;
|
||||||
|
-*) usage "unknown option $1"; exit 42;;
|
||||||
*)
|
*) usage "unknown or missing command $1"; exit 42;;
|
||||||
usage "unknown or missing command $1"; exit 42;;
|
|
||||||
esac
|
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() {
|
build_instances() {
|
||||||
rst_title "Build LXC instances"
|
rst_title "Build LXC instances"
|
||||||
|
|
||||||
rst_title "copy images" section
|
|
||||||
echo
|
echo
|
||||||
|
add_subordinate_ids
|
||||||
lxc_copy_images_localy
|
lxc_copy_images_localy
|
||||||
# lxc image list local: && wait_key
|
|
||||||
echo
|
echo
|
||||||
rst_title "build containers" section
|
rst_title "build containers" section
|
||||||
echo
|
echo
|
||||||
|
@ -272,64 +268,141 @@ build_instances() {
|
||||||
lxc_config_containers
|
lxc_config_containers
|
||||||
lxc_boilerplate_containers
|
lxc_boilerplate_containers
|
||||||
echo
|
echo
|
||||||
lxc list "$HOST_PREFIX"
|
lxc list "$LXC_HOST_PREFIX"
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_instances() {
|
remove_instances() {
|
||||||
rst_title "Remove LXC instances"
|
rst_title "Remove LXC instances"
|
||||||
lxc list "$HOST_PREFIX"
|
rst_para "existing containers matching ${_BGreen}$LXC_HOST_PREFIX-*${_creset}"
|
||||||
echo -en "\\nLXC containers(s)::\\n\\n ${LOCAL_IMAGES[*]}\\n" | $FMT
|
echo
|
||||||
if ask_yn "Do you really want to delete all images"; then
|
lxc list "$LXC_HOST_PREFIX-"
|
||||||
lxc_delete_containers
|
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
|
fi
|
||||||
echo
|
echo
|
||||||
lxc list "$HOST_PREFIX"
|
lxc list "$LXC_HOST_PREFIX-"
|
||||||
# lxc image list local: && wait_key
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# images
|
# images
|
||||||
# ------
|
# ------
|
||||||
|
|
||||||
lxc_copy_images_localy() {
|
lxc_copy_images_localy() {
|
||||||
for ((i=0; i<${#TEST_IMAGES[@]}; i+=2)); do
|
rst_title "copy images" section
|
||||||
if lxc image info "local:${TEST_IMAGES[i+1]}" &>/dev/null; then
|
echo
|
||||||
info_msg "image ${TEST_IMAGES[i]} already copied --> ${TEST_IMAGES[i+1]}"
|
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
|
else
|
||||||
info_msg "copy image locally ${TEST_IMAGES[i]} --> ${TEST_IMAGES[i+1]}"
|
info_msg "copy image locally ${LXC_SUITE[i]} --> ${LXC_SUITE[i+1]}"
|
||||||
lxc image copy "${TEST_IMAGES[i]}" local: \
|
lxc image copy "${LXC_SUITE[i]}" local: \
|
||||||
--alias "${TEST_IMAGES[i+1]}" | prefix_stdout
|
--alias "${LXC_SUITE[i+1]}" | prefix_stdout
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
# lxc image list local: && wait_key
|
||||||
}
|
}
|
||||||
|
|
||||||
lxc_delete_images_localy() {
|
lxc_delete_images_localy() {
|
||||||
|
rst_title "Delete LXC images"
|
||||||
|
rst_para "local existing images"
|
||||||
echo
|
echo
|
||||||
|
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
|
for i in "${LOCAL_IMAGES[@]}"; do
|
||||||
info_msg "delete image 'local:$i'"
|
lxc_delete_local_image "$i"
|
||||||
lxc image delete "local:$i"
|
|
||||||
done
|
done
|
||||||
#lxc image list local:
|
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
|
# container
|
||||||
# ---------
|
# ---------
|
||||||
|
|
||||||
|
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() {
|
lxc_cmd() {
|
||||||
for i in "${LOCAL_IMAGES[@]}"; do
|
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"
|
info_msg "lxc $* $i"
|
||||||
lxc "$@" "$i" | prefix_stdout "[${_BBlue}${i}${_creset}] "
|
lxc "$@" "$i" | prefix_stdout "[${_BBlue}${i}${_creset}] "
|
||||||
|
echo
|
||||||
|
fi
|
||||||
done
|
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() {
|
lxc_init_containers() {
|
||||||
|
|
||||||
local image_name
|
local image_name
|
||||||
local container_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]}"
|
image_name="${LXC_SUITE[i+1]}"
|
||||||
container_name="${HOST_PREFIX}-${image_name}"
|
container_name="${LXC_HOST_PREFIX}-${image_name}"
|
||||||
|
|
||||||
if lxc info "${container_name}" &>/dev/null; then
|
if lxc info "${container_name}" &>/dev/null; then
|
||||||
info_msg "container '${container_name}' already exists"
|
info_msg "container '${container_name}' already exists"
|
||||||
|
@ -341,7 +414,7 @@ lxc_init_containers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
lxc_config_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}] configure container ..."
|
||||||
|
|
||||||
info_msg "[${_BBlue}${i}${_creset}] map uid/gid from host to container"
|
info_msg "[${_BBlue}${i}${_creset}] map uid/gid from host to container"
|
||||||
|
@ -364,10 +437,10 @@ lxc_boilerplate_containers() {
|
||||||
local container_name
|
local container_name
|
||||||
local boilerplate_script
|
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]}"
|
image_name="${LXC_SUITE[i+1]}"
|
||||||
container_name="${HOST_PREFIX}-${image_name}"
|
container_name="${LXC_HOST_PREFIX}-${image_name}"
|
||||||
boilerplate_script="${image_name}_boilerplate"
|
boilerplate_script="${image_name}_boilerplate"
|
||||||
boilerplate_script="${!boilerplate_script}"
|
boilerplate_script="${!boilerplate_script}"
|
||||||
|
|
||||||
|
@ -386,18 +459,6 @@ lxc_boilerplate_containers() {
|
||||||
done
|
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
|
# subordinates
|
||||||
# ------------
|
# ------------
|
||||||
#
|
#
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# shellcheck source=utils/lib.sh
|
# shellcheck source=utils/lib.sh
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||||
source_dot_config
|
source_dot_config
|
||||||
source "${REPO_ROOT}/utils/lxc.env"
|
source "${REPO_ROOT}/utils/lxc-searx.env"
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# config
|
# config
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# shellcheck source=utils/lib.sh
|
# shellcheck source=utils/lib.sh
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
|
||||||
source_dot_config
|
source_dot_config
|
||||||
source "${REPO_ROOT}/utils/lxc.env"
|
source "${REPO_ROOT}/utils/lxc-searx.env"
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# config
|
# config
|
||||||
|
@ -544,13 +544,13 @@ EOF
|
||||||
uWSGI_app_available "$SEARX_UWSGI_APP" \
|
uWSGI_app_available "$SEARX_UWSGI_APP" \
|
||||||
|| err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
|
|| err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
|
||||||
|
|
||||||
if is_container; then
|
if in_container; then
|
||||||
warn_msg "runnning inside container ..."
|
warn_msg "runnning inside container ..."
|
||||||
for ip in $(hostname -I); do
|
for ip in $(global_IPs); do
|
||||||
if [[ $ip =~ .*:.* ]]; then
|
if [[ $ip =~ .*:.* ]]; then
|
||||||
info_msg " public HTTP service (IPv6) --> http://[$ip]"
|
info_msg " public HTTP service (IPv6) --> http://${ip#*|}"
|
||||||
else
|
else
|
||||||
info_msg " public HTTP service (IPv4) --> http://$ip"
|
info_msg " public HTTP service (IPv4) --> http://${ip#*|}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
warn_msg "SEARX_INTERNAL_URL not available from outside"
|
warn_msg "SEARX_INTERNAL_URL not available from outside"
|
||||||
|
@ -564,7 +564,7 @@ EOF
|
||||||
|
|
||||||
if ! service_is_available "${PUBLIC_URL}"; then
|
if ! service_is_available "${PUBLIC_URL}"; then
|
||||||
warn_msg "Public service at ${PUBLIC_URL} is not available!"
|
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."
|
warn_msg "Check if public name is correct and routed or use the public IP from above."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue