@@ -32,11 +32,11 @@ SEARX_PYENV="${SERVICE_HOME}/searx-pyenv"
3232SEARX_SRC="${SERVICE_HOME}/searx-src"
3333SEARX_SETTINGS="${SEARX_SRC}/searx/settings.yml"
3434SEARX_INSTANCE_NAME="${SEARX_INSTANCE_NAME:-searx@$(uname -n)}"
35−SEARX_UWSGI_APP="${uWSGI_SETUP}/apps-available/searx.ini"
35+SEARX_UWSGI_APP="searx.ini"
3636
3737# shellcheck disable=SC2034
3838CONFIG_FILES=(
39− "${SEARX_UWSGI_APP}"
39+ "${uWSGI_SETUP}/apps-available/${SEARX_UWSGI_APP}"
4040)
4141
4242# shellcheck disable=SC2034
@@ -45,7 +45,7 @@ CONFIG_BACKUP_ENCRYPTED=(
4545)
4646
4747# ----------------------------------------------------------------------------
48−usage(){
48+usage() {
4949# ----------------------------------------------------------------------------
5050
5151 # shellcheck disable=SC1117
@@ -60,6 +60,7 @@ usage:
6060 $(basename "$0") activate [service]
6161 $(basename "$0") deactivate [service]
6262 $(basename "$0") show [service]
63+ $(basename "$0") option [debug-on|debug-off]
6364
6465shell
6566 start interactive shell from user ${SERVICE_USER}
@@ -75,12 +76,14 @@ activate
7576deactivate service
7677 stop and deactivate service daemon (systemd unit)
7778show service
78− show service status and log
79+ run some small tests and show service's status and log
80+option
81+ set one of te available options
7982EOF
8083 [ ! -z ${1+x} ] && echo -e "$1"
8184}
8285
83−main(){
86+main() {
8487 rst_title "$SERVICE_NAME" part
8588
8689 local _usage="ERROR: unknown or missing $1 command $2"
@@ -128,13 +131,21 @@ main(){
128131 activate)
129132 sudo_or_exit
130133 case $2 in
131− service) activate_service ;;
134+ service)
135+ activate_service; uWSGI_restart ;;
132136 *) usage "$_usage"; exit 42;;
133137 esac ;;
134138 deactivate)
135139 sudo_or_exit
136140 case $2 in
137− service) deactivate_service ;;
141+ service) deactivate_service; uWSGI_restart ;;
142+ *) usage "$_usage"; exit 42;;
143+ esac ;;
144+ option)
145+ sudo_or_exit
146+ case $2 in
147+ debug-on) echo; enable_debug ;;
148+ debug-off) echo; disable_debug ;;
138149 *) usage "$_usage"; exit 42;;
139150 esac ;;
140151 *) usage "ERROR: unknown or missing command $1"; exit 42;;
@@ -158,6 +169,11 @@ install_all() {
158169 test_local_searx
159170 wait_key
160171 install_searx_uwsgi
172+ if service_is_available; then
173+ info_msg "URL http://$SEARX_URL is available."
174+ else
175+ err_msg "URL http://$SEARX_URL not available, check searx & uwsgi setup!"
176+ fi
161177 wait_key
162178
163179 # ToDo ...
@@ -224,6 +240,10 @@ remove_all() {
224240 remove_user
225241}
226242
243+user_is_available() {
244+ sudo -i -u "$SERVICE_USER" echo \$HOME &>/dev/null
245+}
246+
227247assert_user() {
228248 rst_title "user $SERVICE_USER" section
229249 echo
@@ -247,8 +267,12 @@ remove_user() {
247267 fi
248268}
249269
270+clone_is_available() {
271+ [[ -f "$SEARX_SETTINGS" ]]
272+}
273+
250274# shellcheck disable=SC2164
251−clone_searx(){
275+clone_searx() {
252276 rst_title "Clone searx sources" section
253277 echo
254278 SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME 2>/dev/null)"
@@ -280,7 +304,11 @@ remove_searx() {
280304 fi
281305}
282306
283−create_pyenv(){
307+pyenv_is_available() {
308+ [[ -f "${SEARX_PYENV}/bin/activate" ]]
309+}
310+
311+create_pyenv() {
284312 rst_title "Create virtualenv (python)" section
285313 echo
286314 if [[ ! -f "${SEARX_SRC}/manage.sh" ]]; then
@@ -305,7 +333,7 @@ ${SEARX_SRC}/manage.sh update_packages
305333EOF
306334}
307335
308−remove_pyenv(){
336+remove_pyenv() {
309337 rst_title "Remove virtualenv (python)" section
310338 if ! ask_yn "Do you really want to drop ${SEARX_PYENV} ?"; then
311339 return
@@ -318,7 +346,7 @@ EOF
318346 rm -rf "${SEARX_PYENV}"
319347}
320348
321−configure_searx(){
349+configure_searx() {
322350 rst_title "Configure searx" section
323351 rst_para "Setup searx config located at $SEARX_SETTINGS"
324352 echo
@@ -329,7 +357,7 @@ sed -i -e "s/{instance_name}/${SEARX_INSTANCE_NAME}/g" "$SEARX_SETTINGS"
329357EOF
330358}
331359
332−test_local_searx(){
360+test_local_searx() {
333361 rst_title "Testing searx instance localy" section
334362 echo
335363 tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
@@ -337,7 +365,7 @@ cd ${SEARX_SRC}
337365sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS"
338366timeout 5 python3 searx/webapp.py &
339367sleep 1
340−curl --location --verbose --head --insecure http://127.0.0.1:8888/
368+curl --location --verbose --head --insecure $SEARX_URL
341369sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
342370EOF
343371}
@@ -354,39 +382,106 @@ remove_searx_uwsgi() {
354382 uWSGI_remove_app "$SEARX_UWSGI_APP"
355383}
356384
357−activate_service () {
385+activate_service() {
358386 rst_title "Activate $SERVICE_NAME (service)" section
387+ echo
359388 uWSGI_enable_app "$SEARX_UWSGI_APP"
360389}
361390
362−deactivate_service () {
391+deactivate_service() {
363392 rst_title "De-Activate $SERVICE_NAME (service)" section
393+ echo
364394 uWSGI_disable_app "$SEARX_UWSGI_APP"
365395}
366396
367−interactive_shell(){
397+interactive_shell() {
368398 echo "// exit with CTRL-D"
369399 sudo -H -u "${SERVICE_USER}" -i
370400}
371401
372−git_diff(){
402+git_diff() {
373403 sudo -H -u "${SERVICE_USER}" -i <<EOF
374404cd ${SEARX_REPO_FOLDER}
375405git --no-pager diff
376406EOF
377407}
378408
379−show_service () {
409+service_is_available() {
410+ curl --insecure "http://$SEARX_URL" &>/dev/null
411+}
412+
413+enable_debug() {
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"
416+cd ${SEARX_SRC}
417+sed -i -e "s/debug : False/debug : True/g" "$SEARX_SETTINGS"
418+EOF
419+ uWSGI_restart
420+}
421+
422+disable_debug() {
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"
425+cd ${SEARX_SRC}
426+sed -i -e "s/debug : True/debug : False/g" "$SEARX_SETTINGS"
427+EOF
428+ uWSGI_restart
429+}
430+
431+
432+show_service() {
380433 rst_title "service status & log"
381434 echo
382− systemctl status uwsgi.service
435+
436+ if user_is_available; then
437+ info_msg "service account $SERVICE_USER available."
438+ else
439+ err_msg "service account $SERVICE_USER not available!"
440+ fi
441+ if service_is_available; then
442+ info_msg "URL http://$SEARX_URL is available."
443+ else
444+ err_msg "URL http://$SEARX_URL not available!"
445+ fi
446+ if pyenv_is_available; then
447+ info_msg "${SEARX_PYENV}/bin/activate is available."
448+ else
449+ err_msg "${SEARX_PYENV}/bin/activate not available!"
450+ fi
451+ if clone_is_available; then
452+ info_msg "Searx software is installed."
453+ else
454+ err_msg "Missing searx software!"
455+ fi
456+
457+ uWSGI_app_available "$SEARX_UWSGI_APP" \
458+ || err_msg "uWSGI app $SEARX_UWSGI_APP not available!"
459+
460+ if uWSGI_app_enabled "$SEARX_UWSGI_APP"; then
461+ info_msg "uWSGI app $SEARX_UWSGI_APP is enabled."
462+ else
463+ err_msg "uWSGI app $SEARX_UWSGI_APP not enabled!"
464+ fi
465+
466+ local _debug_on
467+ if ask_yn "Enable searx debug mode?"; then
468+ enable_debug
469+ _debug_on=1
470+ fi
471+ wait_key
383472 echo
384− read -r -s -n1 -t 5 -p "// use CTRL-C to stop monitoring the log"
473+ systemctl status uwsgi.service
474+ read -r -s -n1 -t 2 -p "// use CTRL-C to stop monitoring the log"
385475 echo
386476 while true; do
387477 trap break 2
388− journalctl -f -u uwsgi.service
478+ #journalctl -f -u uwsgi.service
479+ tail -f /var/log/uwsgi/app/searx.log
389480 done
481+
482+ if [[ $_debug_on == 1 ]]; then
483+ disable_debug
484+ fi
390485 return 0
391486}
392487