Browse Source

LXC: from searx.sh, morty.sh and filtron.sh tests

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Markus Heiser 5 years ago
parent
commit
e7f69b63f1
4 changed files with 99 additions and 41 deletions
  1. 14 4
      utils/filtron.sh
  2. 27 11
      utils/lxc.sh
  3. 26 7
      utils/morty.sh
  4. 32 19
      utils/searx.sh

+ 14 - 4
utils/filtron.sh

@@ -7,6 +7,7 @@
 source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
 source_dot_config
 source "${REPO_ROOT}/utils/lxc-searx.env"
+in_container && lxc_set_suite_env
 
 # ----------------------------------------------------------------------------
 # config
@@ -329,16 +330,25 @@ EOF
     fi
 
     if ! service_is_available "${PUBLIC_URL}"; then
-        err_msg "Public service at ${PUBLIC_URL} is not available!"
-        wait_key
+        warn_msg "Public service at ${PUBLIC_URL} is not available!"
+        if ! in_container; then
+            warn_msg "Check if public name is correct and routed or use the public IP from above."
+        fi
     fi
 
+    if in_container; then
+        lxc_suite_info
+    else
+        info_msg "public URL   --> ${PUBLIC_URL}"
+        info_msg "internal URL --> http://${FILTRON_LISTEN}"
+    fi
+
+
     local _debug_on
     if ask_yn "Enable filtron debug mode?"; then
         enable_debug
         _debug_on=1
     fi
-
     echo
     systemctl --no-pager -l status "${SERVICE_NAME}"
     echo
@@ -346,7 +356,7 @@ EOF
     info_msg "public URL --> ${PUBLIC_URL}"
     # shellcheck disable=SC2059
     printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
-    read -r -s -n1 -t 2
+    read -r -s -n1 -t 5
     echo
     while true;  do
         trap break 2

+ 27 - 11
utils/lxc.sh

@@ -108,15 +108,29 @@ cmd
 install
   :suite:        install LXC suite, includes morty & filtron
 
-Images of the LXC suite:
-$(echo "  ${LOCAL_IMAGES[*]}" | $FMT)
+EOF
+    usage_images
+    echo
+    usage_containers
+    echo
+    [ -n "${1+x}" ] &&  err_msg "$1"
+}
 
-Containers of the LXC suite:
+usage_containers() {
+    cat <<EOF
+LXC suite containers:
 $(echo "  ${CONTAINERS[*]}" | $FMT)
 EOF
     [ -n "${1+x}" ] &&  err_msg "$1"
 }
 
+usage_images() {
+    cat <<EOF
+LXC suite images:
+$(echo "  ${LOCAL_IMAGES[*]}" | $FMT)
+EOF
+}
+
 lxd_info() {
 
     cat <<EOF
@@ -164,11 +178,12 @@ main() {
                 images) lxc_delete_images_localy ;;
                 subordinate) echo; del_subordinate_ids ;;
                 ${LXC_HOST_PREFIX}-*)
+                    ! lxc_exists "$2" && usage_containers "unknown container: $2" && exit 42
                     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;;
+                *) usage "uknown or missing container <name> $2"; exit 42;;
             esac
             ;;
         add)
@@ -183,10 +198,11 @@ main() {
             case $2 in
                 ''|containers)  lxc_cmd "$1" ;;
                 ${LXC_HOST_PREFIX}-*)
+                    ! lxc_exists "$2" && usage_containers "unknown container: $2" && exit 42
                     info_msg "lxc $1 $2"
                     lxc "$1" "$2" | prefix_stdout "[${_BBlue}${i}${_creset}] "
                     ;;
-                *) usage "ukknown or missing container <name> $2"; exit 42;;
+                *) usage "uknown or missing container <name> $2"; exit 42;;
             esac
             ;;
         show)
@@ -225,13 +241,12 @@ main() {
                     done
                     ;;
                 ${LXC_HOST_PREFIX}-*)
+                    ! lxc_exists "$1" && usage_containers "unknown container: $1" && exit 42
                     local name=$1
                     shift
                     lxc_exec_cmd "${name}" "$@"
                     ;;
-
-                *) usage "unknown <name>: $1"; exit 42
-                   ;;
+                *) usage "uknown or missing container <name> $2"; exit 42;;
             esac
             ;;
         install)
@@ -351,6 +366,7 @@ show_suite(){
         else
             lxc exec -t "${i}" -- "${LXC_REPO_ROOT}/utils/lxc.sh" __show suite \
                 | prefix_stdout "[${_BBlue}${i}${_creset}]  "
+            echo
         fi
     done
 }
@@ -384,12 +400,12 @@ lxc_exec_cmd() {
     shift
     exit_val=
     info_msg "[${_BBlue}${name}${_creset}] ${_BGreen}${*}${_creset}"
-    lxc exec "${name}" -- "$@"
+    lxc exec --cwd "${LXC_REPO_ROOT}" "${name}" -- "$@"
     exit_val=$?
     if [[ $exit_val -ne 0 ]]; then
-        warn_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
+        warn_msg "[${_BBlue}${name}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
     else
-        info_msg "[${_BBlue}${i}${_creset}] exit code (${exit_val}) from ${_BGreen}${*}${_creset}"
+        info_msg "[${_BBlue}${name}${_creset}] exit code (${exit_val}) from ${_BGreen}${*}${_creset}"
     fi
     echo
 }

+ 26 - 7
utils/morty.sh

@@ -6,6 +6,7 @@
 source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
 source_dot_config
 source "${REPO_ROOT}/utils/lxc-searx.env"
+in_container && lxc_set_suite_env
 
 # ----------------------------------------------------------------------------
 # config
@@ -83,7 +84,14 @@ ${DOT_CONFIG#"$REPO_ROOT/"} file::
 
   MORTY_LISTEN :   ${MORTY_LISTEN}
   SERVICE_USER :   ${SERVICE_USER}
+
 EOF
+    if in_container; then
+        lxc_suite_info
+    else
+        info_msg "public URL   --> ${PUBLIC_URL}"
+        info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
+    fi
     info_searx
     [[ -n ${1} ]] &&  err_msg "$1"
 }
@@ -333,21 +341,32 @@ EOF
         wait_key
     fi
 
+    if ! service_is_available "${PUBLIC_URL}"; then
+        warn_msg "Public service at ${PUBLIC_URL} is not available!"
+        if ! in_container; then
+            warn_msg "Check if public name is correct and routed or use the public IP from above."
+        fi
+    fi
+
+    if in_container; then
+        lxc_suite_info
+    else
+        info_msg "public URL --> ${PUBLIC_URL_MORTY}"
+        info_msg "morty URL --> http://${MORTY_LISTEN}"
+    fi
+
     local _debug_on
-    if ask_yn "Enable filtron debug mode?"; then
+    if ask_yn "Enable filtron debug mode (needs reinstall of systemd service)?"; then
         enable_debug
         _debug_on=1
+    else
+        systemctl --no-pager -l status "${SERVICE_NAME}"
     fi
-
-    echo
-    systemctl --no-pager -l status "${SERVICE_NAME}"
     echo
 
-    info_msg "morty URL --> http://${MORTY_LISTEN}"
-    info_msg "public URL --> ${PUBLIC_URL_MORTY}"
     # shellcheck disable=SC2059
     printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
-    read -r -s -n1 -t 2
+    read -r -s -n1 -t 5
     echo
     while true;  do
         trap break 2

+ 32 - 19
utils/searx.sh

@@ -7,6 +7,7 @@
 source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
 source_dot_config
 source "${REPO_ROOT}/utils/lxc-searx.env"
+in_container && lxc_set_suite_env
 
 # ----------------------------------------------------------------------------
 # config
@@ -223,6 +224,11 @@ install_all() {
     rst_title "Install $SEARX_INSTANCE_NAME (service)"
     pkg_install "$SEARX_PACKAGES"
     wait_key
+    case $DIST_ID-$DIST_VERS in
+        fedora-*)
+            systemctl enable uwsgi
+            ;;
+    esac
     assert_user
     wait_key
     clone_searx
@@ -545,26 +551,21 @@ EOF
         || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
 
     if in_container; then
-        warn_msg "runnning inside container ..."
-        for ip in $(global_IPs); do
-            if [[ $ip =~ .*:.* ]]; then
-                info_msg "  public HTTP service (IPv6) --> http://${ip#*|}"
-            else
-                info_msg "  public HTTP service (IPv4) --> http://${ip#*|}"
-            fi
-        done
-        warn_msg "SEARX_INTERNAL_URL not available from outside"
+        lxc_suite_info
+    else
+        info_msg "public URL   --> ${PUBLIC_URL}"
+        info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
     fi
 
     if ! service_is_available "http://${SEARX_INTERNAL_URL}"; then
         err_msg "uWSGI app (service) at http://${SEARX_INTERNAL_URL} is not available!"
-        echo -e "${_Green}stop with [${_BCyan}CTRL-C${_Green}] or .."
-        wait_key
+        MSG="${_Green}[${_BCyan}CTRL-C${_Green}] to stop or [${_BCyan}KEY${_Green}] to continue"\
+           wait_key
     fi
 
     if ! service_is_available "${PUBLIC_URL}"; then
         warn_msg "Public service at ${PUBLIC_URL} is not available!"
-        if in_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
@@ -575,19 +576,31 @@ EOF
         _debug_on=1
     fi
     echo
-    systemctl --no-pager -l status "${SERVICE_NAME}"
-    echo
 
-    info_msg "public URL   --> ${PUBLIC_URL}"
-    info_msg "internal URL --> http://${SEARX_INTERNAL_URL}"
+    case $DIST_ID-$DIST_VERS in
+        ubuntu-*|debian-*)
+            systemctl --no-pager -l status "${SERVICE_NAME}"
+            ;;
+        arch-*)
+            systemctl --no-pager -l status "uwsgi@${SERVICE_NAME%.*}"
+            ;;
+        fedora-*)
+            systemctl --no-pager -l status uwsgi
+            ;;
+    esac
+
     # shellcheck disable=SC2059
     printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
-    read -r -s -n1 -t 2
+    read -r -s -n1 -t 5
     echo
+
     while true;  do
         trap break 2
-        #journalctl -f -u "${SERVICE_NAME}"
-        tail -f /var/log/uwsgi/app/searx.log
+        case $DIST_ID-$DIST_VERS in
+            ubuntu-*|debian-*) tail -f /var/log/uwsgi/app/searx.log ;;
+            arch-*)  journalctl -f -u "uwsgi@${SERVICE_NAME%.*}" ;;
+            fedora-*)  journalctl -f -u uwsgi ;;
+        esac
     done
 
     if [[ $_debug_on == 1 ]]; then