@@ -32,11 +32,11 @@ SEARX_PYENV="${SERVICE_HOME}/searx-pyenv"
32SEARX_SRC="${SERVICE_HOME}/searx-src"
32SEARX_SRC="${SERVICE_HOME}/searx-src"
33SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
33SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
34SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(uname -n)}"
34SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(uname -n)}"
35−SEARX_UWSGI_APP="${uWSGI_SETUP}/apps-available/searx.ini"
35+SEARX_UWSGI_APP="searx.ini"
37# shellcheck disable=SC2034
37# shellcheck disable=SC2034
38CONFIG_FILES=(
38CONFIG_FILES=(
39− "${SEARX_UWSGI_APP}"
39+ "${uWSGI_SETUP}/apps-available/${SEARX_UWSGI_APP}"
42# shellcheck disable=SC2034
42# shellcheck disable=SC2034
@@ -45,7 +45,7 @@ CONFIG_BACKUP_ENCRYPTED=(
47# ----------------------------------------------------------------------------
47# ----------------------------------------------------------------------------
49# ----------------------------------------------------------------------------
49# ----------------------------------------------------------------------------
51 # shellcheck disable=SC1117
51 # shellcheck disable=SC1117
@@ -60,6 +60,7 @@ usage:
60 $(basename "$0") activate [service]
60 $(basename "$0") activate [service]
61 $(basename "$0") deactivate [service]
61 $(basename "$0") deactivate [service]
62 $(basename "$0") show [service]
62 $(basename "$0") show [service]
63+ $(basename "$0") option [debug-on|debug-off]
65 start interactive shell from user ${SERVICE_USER}
66 start interactive shell from user ${SERVICE_USER}
@@ -75,12 +76,14 @@ activate
75deactivate service
76deactivate service
76 stop and deactivate service daemon (systemd unit)
77 stop and deactivate service daemon (systemd unit)
77show service
78show service
78− show service status and log
79+ run some small tests and show service's status and log
81+ set one of te available options
80 [ ! -z ${1+x} ] && echo -e "$1"
83 [ ! -z ${1+x} ] && echo -e "$1"
84 rst_title "$SERVICE_NAME" part
87 rst_title "$SERVICE_NAME" part
86 local _usage="ERROR: unknown or missing $1 command $2"
89 local _usage="ERROR: unknown or missing $1 command $2"
@@ -128,13 +131,21 @@ main(){
128 activate)
131 activate)
129 sudo_or_exit
132 sudo_or_exit
130 case $2 in
133 case $2 in
131− service) activate_service ;;
135+ activate_service; uWSGI_restart ;;
132 *) usage "$_usage"; exit 42;;
136 *) usage "$_usage"; exit 42;;
134 deactivate)
138 deactivate)
135 sudo_or_exit
139 sudo_or_exit
136 case $2 in
140 case $2 in
137− service) deactivate_service ;;
141+ service) deactivate_service; uWSGI_restart ;;
142+ *) usage "$_usage"; exit 42;;
147+ debug-on) echo; enable_debug ;;
148+ debug-off) echo; disable_debug ;;
138 *) usage "$_usage"; exit 42;;
149 *) usage "$_usage"; exit 42;;
140 *) usage "ERROR: unknown or missing command $1"; exit 42;;
151 *) usage "ERROR: unknown or missing command $1"; exit 42;;
@@ -158,6 +169,11 @@ install_all() {
158 test_local_searx
169 test_local_searx
160 install_searx_uwsgi
171 install_searx_uwsgi
172+ if service_is_available; then
173+ info_msg "URL http://$SEARX_URL is available."
175+ err_msg "URL http://$SEARX_URL not available, check searx & uwsgi setup!"
163 # ToDo ...
179 # ToDo ...
@@ -224,6 +240,10 @@ remove_all() {
224 remove_user
240 remove_user
243+user_is_available() {
244+ sudo -i -u "$SERVICE_USER" echo \$HOME &>/dev/null
227assert_user() {
247assert_user() {
228 rst_title "user $SERVICE_USER" section
248 rst_title "user $SERVICE_USER" section
@@ -247,8 +267,12 @@ remove_user() {
270+clone_is_available() {
271+ [[ -f "$SEARX_SETTINGS" ]]
250# shellcheck disable=SC2164
274# shellcheck disable=SC2164
251−clone_searx(){
275+clone_searx() {
252 rst_title "Clone searx sources" section
276 rst_title "Clone searx sources" section
254 SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME 2>/dev/null)"
278 SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME 2>/dev/null)"
@@ -280,7 +304,11 @@ remove_searx() {
307+pyenv_is_available() {
308+ [[ -f "${SEARX_PYENV}/bin/activate" ]]
283−create_pyenv(){
311+create_pyenv() {
284 rst_title "Create virtualenv (python)" section
312 rst_title "Create virtualenv (python)" section
286 if [[ ! -f "${SEARX_SRC}/manage.sh" ]]; then
314 if [[ ! -f "${SEARX_SRC}/manage.sh" ]]; then
@@ -305,7 +333,7 @@ ${SEARX_SRC}/manage.sh update_packages
308−remove_pyenv(){
336+remove_pyenv() {
309 rst_title "Remove virtualenv (python)" section
337 rst_title "Remove virtualenv (python)" section
310 if ! ask_yn "Do you really want to drop ${SEARX_PYENV} ?"; then
338 if ! ask_yn "Do you really want to drop ${SEARX_PYENV} ?"; then
@@ -318,7 +346,7 @@ EOF
318 rm -rf "${SEARX_PYENV}"
346 rm -rf "${SEARX_PYENV}"
321−configure_searx(){
349+configure_searx() {
322 rst_title "Configure searx" section
350 rst_title "Configure searx" section
323 rst_para "Setup searx config located at $SEARX_SETTINGS"
351 rst_para "Setup searx config located at $SEARX_SETTINGS"
@@ -329,7 +357,7 @@ sed -i -e "s/{instance_name}/${SEARX_INSTANCE_NAME}/g" "$SEARX_SETTINGS"
332−test_local_searx(){
360+test_local_searx() {
333 rst_title "Testing searx instance localy" section
361 rst_title "Testing searx instance localy" section
335 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
363 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
@@ -337,7 +365,7 @@ cd ${SEARX_SRC}
337sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS"
365sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS"
338timeout 5 python3 searx/webapp.py &
366timeout 5 python3 searx/webapp.py &
340−curl --location --verbose --head --insecure http://127.0.0.1:8888/
368+curl --location --verbose --head --insecure $SEARX_URL
341sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
369sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
@@ -354,39 +382,106 @@ remove_searx_uwsgi() {
354 uWSGI_remove_app "$SEARX_UWSGI_APP"
382 uWSGI_remove_app "$SEARX_UWSGI_APP"
357−activate_service () {
385+activate_service() {
358 rst_title "Activate $SERVICE_NAME (service)" section
386 rst_title "Activate $SERVICE_NAME (service)" section
359 uWSGI_enable_app "$SEARX_UWSGI_APP"
388 uWSGI_enable_app "$SEARX_UWSGI_APP"
362−deactivate_service () {
391+deactivate_service() {
363 rst_title "De-Activate $SERVICE_NAME (service)" section
392 rst_title "De-Activate $SERVICE_NAME (service)" section
364 uWSGI_disable_app "$SEARX_UWSGI_APP"
394 uWSGI_disable_app "$SEARX_UWSGI_APP"
367−interactive_shell(){
397+interactive_shell() {
368 echo "// exit with CTRL-D"
398 echo "// exit with CTRL-D"
369 sudo -H -u "${SERVICE_USER}" -i
399 sudo -H -u "${SERVICE_USER}" -i
372−git_diff(){
402+git_diff() {
373 sudo -H -u "${SERVICE_USER}" -i <<EOF
403 sudo -H -u "${SERVICE_USER}" -i <<EOF
374cd ${SEARX_REPO_FOLDER}
404cd ${SEARX_REPO_FOLDER}
375git --no-pager diff
405git --no-pager diff
409+service_is_available() {
410+ curl --insecure "http://$SEARX_URL" &>/dev/null
414+ info_msg "try to enable debug mode ..."
415+ tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
417+sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS"
423+ info_msg "try to disable debug mode ..."
424+ tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
426+sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
379−show_service () {
432+show_service() {
380 rst_title "service status & log"
433 rst_title "service status & log"
382− systemctl status uwsgi.service
435+
436+ if user_is_available; then
437+ info_msg "service account $SERVICE_USER available."
439+ err_msg "service account $SERVICE_USER not available!"
441+ if service_is_available; then
442+ info_msg "URL http://$SEARX_URL is available."
444+ err_msg "URL http://$SEARX_URL not available!"
446+ if pyenv_is_available; then
447+ info_msg "${SEARX_PYENV}/bin/activate is available."
449+ err_msg "${SEARX_PYENV}/bin/activate not available!"
451+ if clone_is_available; then
452+ info_msg "Searx software is installed."
454+ err_msg "Missing searx software!"
457+ uWSGI_app_available "$SEARX_UWSGI_APP" \
458+ || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
460+ if uWSGI_app_enabled "$SEARX_UWSGI_APP"; then
461+ info_msg "uWSGI app $SEARX_UWSGI_APP is enabled."
463+ err_msg "uWSGI app $SEARX_UWSGI_APP not enabled!"
467+ if ask_yn "Enable searx debug mode?"; then
473+ systemctl status uwsgi.service
384− read -r -s -n1 -t 5 -p "// use CTRL-C to stop monitoring the log"
474+ read -r -s -n1 -t 2 -p "// use CTRL-C to stop monitoring the log"
386 while true; do
476 while true; do
387 trap break 2
477 trap break 2
388− journalctl -f -u uwsgi.service
478+ #journalctl -f -u uwsgi.service
479+ tail -f /var/log/uwsgi/app/searx.log
482+ if [[ $_debug_on == 1 ]]; then