on master help sign in
utils/searx.sh: add script to install isolated searx service
9b5a7f7Markus Heiser
utils/lib.sh+41−23
@@ -373,66 +373,84 @@ uWSGI_restart() {
373 sudo -H systemctl restart uwsgi
373 sudo -H systemctl restart uwsgi
374}
374}
375
375
376+uWSGI_app_available() {
377+ # usage: uWSGI_app_available <myapp.ini>
378+ local CONF="$1"
379+ if [[ -z $CONF ]]; then
380+ err_msg "uWSGI_app_available: missing arguments"
381+ return 42
382+ fi
383+ [[ -f "${uWSGI_SETUP}/apps-available/${CONF}" ]]
384+}
385+
376uWSGI_install_app() {
386uWSGI_install_app() {
377
387
378− # usage: uWSGI_install_app [--no-eval] /etc/uwsgi/apps-available/myapp.ini
388+ # usage: uWSGI_install_app [--no-eval] <myapp.ini>
379
389
380 local no_eval=""
390 local no_eval=""
381− local CONF=""
391+ local CONF="$1"
382
392
383 if [[ "$1" == "--no-eval" ]]; then
393 if [[ "$1" == "--no-eval" ]]; then
384 no_eval=$1; shift
394 no_eval=$1; shift
385 fi
395 fi
386
396
387− CONF=$1
388 # shellcheck disable=SC2086
397 # shellcheck disable=SC2086
389− install_template $no_eval "${CONF}" root root 644
398+ install_template $no_eval "${uWSGI_SETUP}/apps-available/${CONF}" root root 644
390− uWSGI_enable_app "$(basename "${CONF}")"
399+ uWSGI_enable_app "${CONF}"
391 uWSGI_restart
400 uWSGI_restart
392− info_msg "installed uWSGI app: $(basename "${CONF}")"
401+ info_msg "installed uWSGI app: ${CONF}"
393}
402}
394
403
395uWSGI_remove_app() {
404uWSGI_remove_app() {
396
405
397− # usage: uWSGI_remove_app <path.ini>
406+ # usage: uWSGI_remove_app <myapp.ini>
398
407
399− local CONF=$1
408+ local CONF="$1"
400− uWSGI_disable_app "$(basename "${CONF}")"
409+ uWSGI_disable_app "${CONF}"
401 uWSGI_restart
410 uWSGI_restart
402− rm -f "$CONF"
411+ rm -f "${uWSGI_SETUP}/apps-available/${CONF}"
403− info_msg "removed uWSGI app: $(basename "${CONF}")"
412+ info_msg "removed uWSGI app: ${CONF}"
413+}
414+
415+uWSGI_app_enabled() {
416+ # usage: uWSGI_app_enabled <myapp.ini>
417+ local CONF="$1"
418+ if [[ -z $CONF ]]; then
419+ err_msg "uWSGI_app_enabled: missing arguments"
420+ return 42
421+ fi
422+ [[ -f "${uWSGI_SETUP}/apps-enabled/${CONF}" ]]
404}
423}
405
424
406# shellcheck disable=SC2164
425# shellcheck disable=SC2164
407uWSGI_enable_app() {
426uWSGI_enable_app() {
408
427
409− # usage: uWSGI_enable_app <path.ini>
428+ # usage: uWSGI_enable_app <myapp.ini>
410
429
411− local CONF=$1
430+ local CONF="$1"
412 if [[ -z $CONF ]]; then
431 if [[ -z $CONF ]]; then
413− err_msg "uWSGI_enable_app missing arguments"
432+ err_msg "uWSGI_enable_app: missing arguments"
414 return 42
433 return 42
415 fi
434 fi
416 pushd "${uWSGI_SETUP}/apps-enabled" >/dev/null
435 pushd "${uWSGI_SETUP}/apps-enabled" >/dev/null
417− rm -f "$(basename "${CONF}")"
436+ rm -f "$CONF"
418 # shellcheck disable=SC2226
437 # shellcheck disable=SC2226
419− ln -s "../apps-available/$(basename "${CONF}")"
438+ ln -s "../apps-available/${CONF}"
420− info_msg "enabled uWSGI app: $(basename "${CONF}") (restart uWSGI required)"
439+ info_msg "enabled uWSGI app: ${CONF} (restart uWSGI required)"
421 popd >/dev/null
440 popd >/dev/null
422}
441}
423
442
424uWSGI_disable_app() {
443uWSGI_disable_app() {
425
444
426− # usage: uWSGI_disable_app <path.ini>
445+ # usage: uWSGI_disable_app <myapp.ini>
427
446
428− local CONF=$1
447+ local CONF="$1"
429 if [[ -z $CONF ]]; then
448 if [[ -z $CONF ]]; then
430− err_msg "uWSGI_enable_app missing arguments"
449+ err_msg "uWSGI_enable_app: missing arguments"
431 return 42
450 return 42
432 fi
451 fi
433−
434− rm -f "${uWSGI_SETUP}/apps-enabled/$CONF"
452+ rm -f "${uWSGI_SETUP}/apps-enabled/${CONF}"
435− info_msg "disabled uWSGI app: $(basename "${CONF}") (restart uWSGI required)"
453+ info_msg "disabled uWSGI app: ${CONF} (restart uWSGI required)"
436}
454}
437
455
438# distro's package manager
456# distro's package manager
utils/searx.sh+116−21
@@ -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"
36
36
37# shellcheck disable=SC2034
37# shellcheck disable=SC2034
38CONFIG_FILES=(
38CONFIG_FILES=(
39− "${SEARX_UWSGI_APP}"
39+ "${uWSGI_SETUP}/apps-available/${SEARX_UWSGI_APP}"
40)
40)
41
41
42# shellcheck disable=SC2034
42# shellcheck disable=SC2034
@@ -45,7 +45,7 @@ CONFIG_BACKUP_ENCRYPTED=(
45)
45)
46
46
47# ----------------------------------------------------------------------------
47# ----------------------------------------------------------------------------
48−usage(){
48+usage() {
49# ----------------------------------------------------------------------------
49# ----------------------------------------------------------------------------
50
50
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]
63
64
64shell
65shell
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
80+option
81+ set one of te available options
79EOF
82EOF
80 [ ! -z ${1+x} ] && echo -e "$1"
83 [ ! -z ${1+x} ] && echo -e "$1"
81}
84}
82
85
83−main(){
86+main() {
84 rst_title "$SERVICE_NAME" part
87 rst_title "$SERVICE_NAME" part
85
88
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
134+ service)
131− service) activate_service ;;
135+ activate_service; uWSGI_restart ;;
132 *) usage "$_usage"; exit 42;;
136 *) usage "$_usage"; exit 42;;
133 esac ;;
137 esac ;;
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;;
143+ esac ;;
144+ option)
145+ sudo_or_exit
146+ case $2 in
147+ debug-on) echo; enable_debug ;;
148+ debug-off) echo; disable_debug ;;
138 *) usage "$_usage"; exit 42;;
149 *) usage "$_usage"; exit 42;;
139 esac ;;
150 esac ;;
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
159 wait_key
170 wait_key
160 install_searx_uwsgi
171 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
161 wait_key
177 wait_key
162
178
163 # ToDo ...
179 # ToDo ...
@@ -224,6 +240,10 @@ remove_all() {
224 remove_user
240 remove_user
225}
241}
226
242
243+user_is_available() {
244+ sudo -i -u "$SERVICE_USER" echo \$HOME &>/dev/null
245+}
246+
227assert_user() {
247assert_user() {
228 rst_title "user $SERVICE_USER" section
248 rst_title "user $SERVICE_USER" section
229 echo
249 echo
@@ -247,8 +267,12 @@ remove_user() {
247 fi
267 fi
248}
268}
249
269
270+clone_is_available() {
271+ [[ -f "$SEARX_SETTINGS" ]]
272+}
273+
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
253 echo
277 echo
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() {
280 fi
304 fi
281}
305}
282
306
307+pyenv_is_available() {
308+ [[ -f "${SEARX_PYENV}/bin/activate" ]]
309+}
310+
283−create_pyenv(){
311+create_pyenv() {
284 rst_title "Create virtualenv (python)" section
312 rst_title "Create virtualenv (python)" section
285 echo
313 echo
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
305EOF
333EOF
306}
334}
307
335
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
311 return
339 return
@@ -318,7 +346,7 @@ EOF
318 rm -rf "${SEARX_PYENV}"
346 rm -rf "${SEARX_PYENV}"
319}
347}
320
348
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"
324 echo
352 echo
@@ -329,7 +357,7 @@ sed -i -e "s/{instance_name}/${SEARX_INSTANCE_NAME}/g" "$SEARX_SETTINGS"
329EOF
357EOF
330}
358}
331
359
332−test_local_searx(){
360+test_local_searx() {
333 rst_title "Testing searx instance localy" section
361 rst_title "Testing searx instance localy" section
334 echo
362 echo
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 &
339sleep 1
367sleep 1
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"
342EOF
370EOF
343}
371}
@@ -354,39 +382,106 @@ remove_searx_uwsgi() {
354 uWSGI_remove_app "$SEARX_UWSGI_APP"
382 uWSGI_remove_app "$SEARX_UWSGI_APP"
355}
383}
356
384
357−activate_service () {
385+activate_service() {
358 rst_title "Activate $SERVICE_NAME (service)" section
386 rst_title "Activate $SERVICE_NAME (service)" section
387+ echo
359 uWSGI_enable_app "$SEARX_UWSGI_APP"
388 uWSGI_enable_app "$SEARX_UWSGI_APP"
360}
389}
361
390
362−deactivate_service () {
391+deactivate_service() {
363 rst_title "De-Activate $SERVICE_NAME (service)" section
392 rst_title "De-Activate $SERVICE_NAME (service)" section
393+ echo
364 uWSGI_disable_app "$SEARX_UWSGI_APP"
394 uWSGI_disable_app "$SEARX_UWSGI_APP"
365}
395}
366
396
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
370}
400}
371
401
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
376EOF
406EOF
377}
407}
378
408
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+
379−show_service () {
432+show_service() {
380 rst_title "service status & log"
433 rst_title "service status & log"
381 echo
434 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
383 echo
472 echo
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"
385 echo
475 echo
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
389 done
480 done
481+
482+ if [[ $_debug_on == 1 ]]; then
483+ disable_debug
484+ fi
390 return 0
485 return 0
391}
486}
392
487
utils/templates/etc/uwsgi/apps-available/searx.ini+3−3
@@ -10,7 +10,7 @@ uid = ${SERVICE_USER}
10gid = ${SERVICE_GROUP}
10gid = ${SERVICE_GROUP}
11
11
12# chdir to specified directory before apps loading
12# chdir to specified directory before apps loading
13−chdir = ${SEARX_SRC}
13+chdir = ${SEARX_SRC}/searx
14
14
15# disable logging for privacy
15# disable logging for privacy
16disable-logging = true
16disable-logging = true
@@ -28,7 +28,7 @@ master = true
28lazy-apps = true
28lazy-apps = true
29
29
30# load uWSGI plugins
30# load uWSGI plugins
31−plugin = python3
31+plugin = python3,http
32
32
33# By default the Python plugin does not initialize the GIL. This means your
33# By default the Python plugin does not initialize the GIL. This means your
34# app-generated threads will not run. If you need threads, remember to enable
34# app-generated threads will not run. If you need threads, remember to enable
@@ -50,7 +50,7 @@ module = searx.webapp
50virtualenv = ${SEARX_PYENV}
50virtualenv = ${SEARX_PYENV}
51
51
52# add directory (or glob) to pythonpath
52# add directory (or glob) to pythonpath
53−pythonpath = ${SERVICE_HOME}
53+pythonpath = ${SEARX_SRC}
54
54
55
55
56# plugin http
56# plugin http