summaryrefslogtreecommitdiff
path: root/utils/lxc.sh
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2020-02-27 19:13:03 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2020-02-27 19:13:03 +0100
commit37c135f2cec6113aa2baaf1b52fe46fd64265975 (patch)
tree1f6ee43085d250c8720d11ce4156e28941ac75f0 /utils/lxc.sh
parentaf6acd3417bf53c151b9ba6068186c1e472a2776 (diff)
downloadsearxng-37c135f2cec6113aa2baaf1b52fe46fd64265975.tar.gz
searxng-37c135f2cec6113aa2baaf1b52fe46fd64265975.zip
LXC: improved UX when working with a bunch of containers
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'utils/lxc.sh')
-rwxr-xr-xutils/lxc.sh120
1 files changed, 78 insertions, 42 deletions
diff --git a/utils/lxc.sh b/utils/lxc.sh
index 58528d591..ab9afcbb4 100755
--- a/utils/lxc.sh
+++ b/utils/lxc.sh
@@ -63,6 +63,12 @@ HOST_USER="${SUDO_USER:-$USER}"
HOST_USER_ID=$(id -u "${HOST_USER}")
HOST_GROUP_ID=$(id -g "${HOST_USER}")
+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"
+}
+
# ----------------------------------------------------------------------------
usage() {
# ----------------------------------------------------------------------------
@@ -74,8 +80,8 @@ usage::
$(basename "$0") build [containers]
$(basename "$0") install [searx-suite]
$(basename "$0") remove [containers|subordinate]
- $(basename "$0") [start|stop] [containers]
- $(basename "$0") inspect [info|config]
+ $(basename "$0") [start|stop] [containers|<container-name>]
+ $(basename "$0") show [info|config|searx-suite]
$(basename "$0") cmd ...
build / remove
@@ -83,10 +89,11 @@ build / remove
add / remove
:subordinate: lxd permission to map ${HOST_USER}'s user/group id through
start/stop
- :containers: start/stop of all containers
-inspect
- :info: show info of all containers
- :config: show config of all containers
+ :containers: start/stop of all 'containers' or only <container-name>
+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
install
@@ -116,22 +123,10 @@ main() {
local exit_val
local _usage="unknown or missing $1 command $2"
- case $1 in
- __install)
- sudo_or_exit
- case $2 in
- searx-suite) install_searx_suite ;;
- esac
- exit
- ;;
- *)
- if ! required_commands lxc; then
- lxd_info
- exit 42
- fi
- ;;
- esac
-
+ if [[ ! $1 == __* ]] && ! required_commands lxc; then
+ lxd_info
+ exit 42
+ fi
case $1 in
--source-only) ;;
-h|--help) usage; exit 0;;
@@ -141,20 +136,23 @@ main() {
case $2 in
containers) build_instances ;;
*) usage "$_usage"; exit 42;;
- esac ;;
+ esac
+ ;;
remove)
sudo_or_exit
case $2 in
containers) remove_instances ;;
subordinate) echo; del_subordinate_ids ;;
*) usage "$_usage"; exit 42;;
- esac ;;
+ esac
+ ;;
add)
sudo_or_exit
case $2 in
subordinate) echo; add_subordinate_ids ;;
*) usage "$_usage"; exit 42;;
- esac ;;
+ esac
+ ;;
start|stop)
sudo_or_exit
case $2 in
@@ -163,14 +161,27 @@ main() {
info_msg "lxc $1 $2"
lxc "$1" "$2" | prefix_stdout "[${_BBlue}${i}${_creset}] "
;;
- esac ;;
- inspect)
+ 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
+ ;;
*) usage "$_usage"; exit 42;;
- esac ;;
+ esac
+ ;;
+ __show)
+ case $2 in
+ searx-suite) searx_suite_info ;;
+ esac
+ ;;
cmd)
sudo_or_exit
shift
@@ -192,30 +203,55 @@ main() {
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 "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2"
+ lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __install "$2" | prefix_stdout "[${i}] "
done
;;
*) usage "$_usage"; exit 42;;
- esac ;;
+ esac
+ ;;
+ __install)
+ case $2 in
+ searx-suite) searx_suite_install ;;
+ esac
+ ;;
*)
usage "unknown or missing command $1"; exit 42;;
esac
}
-install_searx_suite() {
- export FILTRON_API="0.0.0.0:4005"
- export FILTRON_LISTEN="0.0.0.0:4004"
- export MORTY_LISTEN="0.0.0.0:3000"
- FORCE_TIMEOUT=0 "${LXC_REPO_ROOT}/utils/searx.sh" install all
- FORCE_TIMEOUT=0 "${LXC_REPO_ROOT}/utils/morty.sh" install all
- FORCE_TIMEOUT=0 "${LXC_REPO_ROOT}/utils/filtron.sh" install all
- rst_title "[$(hostname)] searx-suite installation finished" part
- rst_para "IPs of the container ..."
- echo
- ip addr show | grep "inet\s*[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"
- echo
+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"