on master help sign in
LXC: from searx.sh, morty.sh and filtron.sh tests

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commite7f69b63f1169a60f6f15b827dfe4f5748a41d2c authorMarkus Heiser <markus.heiser@darmarit.de> dateSun 8 Mar 2020, 02:41 (7 years ago) parentb1e90cf
4 files changed+99−41
utils/filtron.sh+14−4 utils/lxc.sh+27−11 utils/morty.sh+26−7 utils/searx.sh+32−19
utils/filtron.sh+14−4
@@ -7,6 +7,7 @@
77source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
88source_dot_config
99source "${REPO_ROOT}/utils/lxc-searx.env"
10+in_container && lxc_set_suite_env
1011
1112# ----------------------------------------------------------------------------
1213# config
@@ -329,16 +330,25 @@ EOF
329330 fi
330331
331332 if ! service_is_available "${PUBLIC_URL}"; then
332− err_msg "Public service at ${PUBLIC_URL} is not available!"
333− wait_key
333+ warn_msg "Public service at ${PUBLIC_URL} is not available!"
334+ if ! in_container; then
335+ warn_msg "Check if public name is correct and routed or use the public IP from above."
336+ fi
334337 fi
335338
339+ if in_container; then
340+ lxc_suite_info
341+ else
342+ info_msg "public URL --> ${PUBLIC_URL}"
343+ info_msg "internal URL --> http://${FILTRON_LISTEN}"
344+ fi
345+
346+
336347 local _debug_on
337348 if ask_yn "Enable filtron debug mode?"; then
338349 enable_debug
339350 _debug_on=1
340351 fi
341−
342352 echo
343353 systemctl --no-pager -l status "${SERVICE_NAME}"
344354 echo
@@ -346,7 +356,7 @@ EOF
346356 info_msg "public URL --> ${PUBLIC_URL}"
347357 # shellcheck disable=SC2059
348358 printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
349− read -r -s -n1 -t 2
359+ read -r -s -n1 -t 5
350360 echo
351361 while true; do
352362 trap break 2
utils/lxc.sh+27−11
@@ -108,15 +108,29 @@ cmd
108108install
109109 :suite: install LXC suite, includes morty & filtron
110110
111−Images of the LXC suite:
112−$(echo " ${LOCAL_IMAGES[*]}" | $FMT)
111+EOF
112+ usage_images
113+ echo
114+ usage_containers
115+ echo
116+ [ -n "${1+x}" ] && err_msg "$1"
117+}
113118
114−Containers of the LXC suite:
119+usage_containers() {
120+ cat <<EOF
121+LXC suite containers:
115122$(echo " ${CONTAINERS[*]}" | $FMT)
116123EOF
117124 [ -n "${1+x}" ] && err_msg "$1"
118125}
119126
127+usage_images() {
128+ cat <<EOF
129+LXC suite images:
130+$(echo " ${LOCAL_IMAGES[*]}" | $FMT)
131+EOF
132+}
133+
120134lxd_info() {
121135
122136 cat <<EOF
@@ -164,11 +178,12 @@ main() {
164178 images) lxc_delete_images_localy ;;
165179 subordinate) echo; del_subordinate_ids ;;
166180 ${LXC_HOST_PREFIX}-*)
181+ ! lxc_exists "$2" && usage_containers "unknown container: $2" && exit 42
167182 if ask_yn "Do you really want to delete conatiner $2"; then
168183 lxc_delete_container "$2"
169184 fi
170185 ;;
171− *) usage "unknown (or mising) container <name> $2"; exit 42;;
186+ *) usage "uknown or missing container <name> $2"; exit 42;;
172187 esac
173188 ;;
174189 add)
@@ -183,10 +198,11 @@ main() {
183198 case $2 in
184199 ''|containers) lxc_cmd "$1" ;;
185200 ${LXC_HOST_PREFIX}-*)
201+ ! lxc_exists "$2" && usage_containers "unknown container: $2" && exit 42
186202 info_msg "lxc $1 $2"
187203 lxc "$1" "$2" | prefix_stdout "[${_BBlue}${i}${_creset}] "
188204 ;;
189− *) usage "ukknown or missing container <name> $2"; exit 42;;
205+ *) usage "uknown or missing container <name> $2"; exit 42;;
190206 esac
191207 ;;
192208 show)
@@ -225,13 +241,12 @@ main() {
225241 done
226242 ;;
227243 ${LXC_HOST_PREFIX}-*)
244+ ! lxc_exists "$1" && usage_containers "unknown container: $1" && exit 42
228245 local name=$1
229246 shift
230247 lxc_exec_cmd "${name}" "$@"
231248 ;;
232−
233− *) usage "unknown <name>: $1"; exit 42
234− ;;
249+ *) usage "uknown or missing container <name> $2"; exit 42;;
235250 esac
236251 ;;
237252 install)
@@ -351,6 +366,7 @@ show_suite(){
351366 else
352367 lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __show suite \
353368 | prefix_stdout "[${_BBlue}${i}${_creset}] "
369+ echo
354370 fi
355371 done
356372}
@@ -384,12 +400,12 @@ lxc_exec_cmd() {
384400 shift
385401 exit_val=
386402 info_msg "[${_BBlue}${name}${_creset}] ${_BGreen}${*}${_creset}"
387− lxc exec "${name}" -- "$@"
403+ lxc exec --cwd "${LXC_REPO_ROOT}" "${name}" -- "$@"
388404 exit_val=$?
389405 if [[ $exit_val -ne 0 ]]; then
390− warn_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
406+ warn_msg "[${_BBlue}${name}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
391407 else
392− info_msg "[${_BBlue}${i}${_creset}] exit code (${exit_val}) from ${_BGreen}${*}${_creset}"
408+ info_msg "[${_BBlue}${name}${_creset}] exit code (${exit_val}) from ${_BGreen}${*}${_creset}"
393409 fi
394410 echo
395411}
utils/morty.sh+26−7
@@ -6,6 +6,7 @@
66source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
77source_dot_config
88source "${REPO_ROOT}/utils/lxc-searx.env"
9+in_container && lxc_set_suite_env
910
1011# ----------------------------------------------------------------------------
1112# config
@@ -83,7 +84,14 @@ ${DOT_CONFIG#"$REPO_ROOT/"} file::
8384
8485 MORTY_LISTEN : ${MORTY_LISTEN}
8586 SERVICE_USER : ${SERVICE_USER}
87+
8688EOF
89+ if in_container; then
90+ lxc_suite_info
91+ else
92+ info_msg "public URL --> ${PUBLIC_URL}"
93+ info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
94+ fi
8795 info_searx
8896 [[ -n ${1} ]] && err_msg "$1"
8997}
@@ -333,21 +341,32 @@ EOF
333341 wait_key
334342 fi
335343
344+ if ! service_is_available "${PUBLIC_URL}"; then
345+ warn_msg "Public service at ${PUBLIC_URL} is not available!"
346+ if ! in_container; then
347+ warn_msg "Check if public name is correct and routed or use the public IP from above."
348+ fi
349+ fi
350+
351+ if in_container; then
352+ lxc_suite_info
353+ else
354+ info_msg "public URL --> ${PUBLIC_URL_MORTY}"
355+ info_msg "morty URL --> http://${MORTY_LISTEN}"
356+ fi
357+
336358 local _debug_on
337− if ask_yn "Enable filtron debug mode?"; then
359+ if ask_yn "Enable filtron debug mode (needs reinstall of systemd service)?"; then
338360 enable_debug
339361 _debug_on=1
362+ else
363+ systemctl --no-pager -l status "${SERVICE_NAME}"
340364 fi
341−
342− echo
343− systemctl --no-pager -l status "${SERVICE_NAME}"
344365 echo
345366
346− info_msg "morty URL --> http://${MORTY_LISTEN}"
347− info_msg "public URL --> ${PUBLIC_URL_MORTY}"
348367 # shellcheck disable=SC2059
349368 printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
350− read -r -s -n1 -t 2
369+ read -r -s -n1 -t 5
351370 echo
352371 while true; do
353372 trap break 2
utils/searx.sh+32−19
@@ -7,6 +7,7 @@
77source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
88source_dot_config
99source "${REPO_ROOT}/utils/lxc-searx.env"
10+in_container && lxc_set_suite_env
1011
1112# ----------------------------------------------------------------------------
1213# config
@@ -223,6 +224,11 @@ install_all() {
223224 rst_title "Install $SEARX_INSTANCE_NAME (service)"
224225 pkg_install "$SEARX_PACKAGES"
225226 wait_key
227+ case $DIST_ID-$DIST_VERS in
228+ fedora-*)
229+ systemctl enable uwsgi
230+ ;;
231+ esac
226232 assert_user
227233 wait_key
228234 clone_searx
@@ -545,26 +551,21 @@ EOF
545551 || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
546552
547553 if in_container; then
548− warn_msg "runnning inside container ..."
549− for ip in $(global_IPs); do
550− if [[ $ip =~ .*:.* ]]; then
551− info_msg " public HTTP service (IPv6) --> http://${ip#*|}"
552− else
553− info_msg " public HTTP service (IPv4) --> http://${ip#*|}"
554− fi
555− done
556− warn_msg "SEARX_INTERNAL_URL not available from outside"
554+ lxc_suite_info
555+ else
556+ info_msg "public URL --> ${PUBLIC_URL}"
557+ info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
557558 fi
558559
559560 if ! service_is_available "http://${SEARX_INTERNAL_URL}"; then
560561 err_msg "uWSGI app (service) at http://${SEARX_INTERNAL_URL} is not available!"
561− echo -e "${_Green}stop with [${_BCyan}CTRL-C${_Green}] or .."
562− wait_key
562+ MSG="${_Green}[${_BCyan}CTRL-C${_Green}] to stop or [${_BCyan}KEY${_Green}] to continue"\
563+ wait_key
563564 fi
564565
565566 if ! service_is_available "${PUBLIC_URL}"; then
566567 warn_msg "Public service at ${PUBLIC_URL} is not available!"
567− if in_container; then
568+ if ! in_container; then
568569 warn_msg "Check if public name is correct and routed or use the public IP from above."
569570 fi
570571 fi
@@ -575,19 +576,31 @@ EOF
575576 _debug_on=1
576577 fi
577578 echo
578− systemctl --no-pager -l status "${SERVICE_NAME}"
579− echo
580579
581− info_msg "public URL --> ${PUBLIC_URL}"
582− info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
580+ case $DIST_ID-$DIST_VERS in
581+ ubuntu-*|debian-*)
582+ systemctl --no-pager -l status "${SERVICE_NAME}"
583+ ;;
584+ arch-*)
585+ systemctl --no-pager -l status "uwsgi@${SERVICE_NAME%.*}"
586+ ;;
587+ fedora-*)
588+ systemctl --no-pager -l status uwsgi
589+ ;;
590+ esac
591+
583592 # shellcheck disable=SC2059
584593 printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
585− read -r -s -n1 -t 2
594+ read -r -s -n1 -t 5
586595 echo
596+
587597 while true; do
588598 trap break 2
589− #journalctl -f -u "${SERVICE_NAME}"
590− tail -f /var/log/uwsgi/app/searx.log
599+ case $DIST_ID-$DIST_VERS in
600+ ubuntu-*|debian-*) tail -f /var/log/uwsgi/app/searx.log ;;
601+ arch-*) journalctl -f -u "uwsgi@${SERVICE_NAME%.*}" ;;
602+ fedora-*) journalctl -f -u uwsgi ;;
603+ esac
591604 done
592605
593606 if [[ $_debug_on == 1 ]]; then