utils/lib.sh: make uWSGI installation available for all distros

support: ubuntu, debin, fedora, archlinux

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2020-02-25 20:20:17 +01:00
parent f5d10abc7f
commit d5917cc029
6 changed files with 136 additions and 11 deletions

View file

@ -84,11 +84,11 @@ test.pylint: pyenvinstall
$(call cmd,pylint,searx/testing.py)
test.sh:
shellcheck -x utils/lxc.sh
shellcheck -x utils/lib.sh
shellcheck -x utils/filtron.sh
shellcheck -x utils/searx.sh
shellcheck -x utils/morty.sh
shellcheck -x utils/lxc.sh
shellcheck -x .config.sh
test.pep8: pyenvinstall

View file

@ -692,18 +692,37 @@ apache_dissable_site() {
# -----
uWSGI_SETUP="${uWSGI_SETUP:=/etc/uwsgi}"
uWSGI_USER=
uWSGI_GROUP=
# How distros manage uWSGI apps is very different. From uWSGI POV read:
# - https://uwsgi-docs.readthedocs.io/en/latest/Management.html
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
# init.d --> /usr/share/doc/uwsgi/README.Debian.gz
# For uWSGI debian uses the LSB init process, this might be changed
# one day, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833067
uWSGI_APPS_AVAILABLE="${uWSGI_SETUP}/apps-available"
uWSGI_APPS_ENABLED="${uWSGI_SETUP}/apps-enabled"
;;
arch-*)
# systemd --> /usr/lib/systemd/system/uwsgi@.service
uWSGI_APPS_AVAILABLE="${uWSGI_SETUP}"
# For uWSGI archlinux uses systemd template units, see
# - http://0pointer.de/blog/projects/instances.html
# - https://uwsgi-docs.readthedocs.io/en/latest/Systemd.html#one-service-per-app-in-systemd
uWSGI_APPS_AVAILABLE="${uWSGI_SETUP}/apps-archlinux"
uWSGI_APPS_ENABLED="${uWSGI_SETUP}"
;;
fedora-*)
# systemd --> /usr/lib/systemd/system/uwsgi.service
# The unit file starts uWSGI in emperor mode (/etc/uwsgi.ini), see
# - https://uwsgi-docs.readthedocs.io/en/latest/Emperor.html
uWSGI_APPS_AVAILABLE="${uWSGI_SETUP}/apps-available"
uWSGI_APPS_ENABLED="${uWSGI_SETUP}.d"
uWSGI_USER="uwsgi"
uWSGI_GROUP="uwsgi"
;;
*)
info_msg "$DIST_ID-$DIST_VERS: uWSGI not yet implemented"
;;
@ -723,10 +742,25 @@ uWSGI_restart() {
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
# the 'service' method seems broken in that way, that it (re-)starts
# the whole uwsgi process.
service uwsgi restart "${CONF%.*}"
;;
arch-*)
systemctl restart "uwsgi@${CONF%.*}"
# restart systemd template instance
if uWSGI_app_available "${CONF}"; then
systemctl restart "uwsgi@${CONF%.*}"
else
info_msg "in systemd template mode: ${CONF} not installed (nothing to restart)"
fi
;;
fedora-*)
# in emperor mode, just touch the file to restart
if uWSGI_app_enabled "${CONF}"; then
touch "${uWSGI_APPS_ENABLED}/${CONF}"
else
info_msg "in uWSGI emperor mode: ${CONF} not installed (nothing to restart)"
fi
;;
*)
err_msg "$DIST_ID-$DIST_VERS: uWSGI not yet implemented"
@ -765,7 +799,7 @@ uWSGI_install_app() {
root root 644
uWSGI_enable_app "${pos_args[1]}"
uWSGI_restart "${pos_args[1]}"
info_msg "installed uWSGI app: ${pos_args[1]}"
info_msg "uWSGI app: ${pos_args[1]} is installed"
}
uWSGI_remove_app() {
@ -797,6 +831,10 @@ uWSGI_app_enabled() {
systemctl -q is-enabled "uwsgi@${CONF%.*}"
exit_val=$?
;;
fedora-*)
[[ -f "${uWSGI_APPS_ENABLED}/${CONF}" ]]
exit_val=$?
;;
*)
# FIXME
err_msg "$DIST_ID-$DIST_VERS: uWSGI not yet implemented"
@ -821,14 +859,22 @@ uWSGI_enable_app() {
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
mkdir -p "${uWSGI_APPS_ENABLED}"
pushd "${uWSGI_APPS_ENABLED}" >/dev/null
rm -f "$CONF"
ln -s "${uWSGI_APPS_AVAILABLE}/${CONF}" .
popd >/dev/null
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
ln -s "${uWSGI_APPS_AVAILABLE}/${CONF}" "${uWSGI_APPS_ENABLED}/${CONF}"
info_msg "enabled uWSGI app: ${CONF} (restart required)"
;;
arch-*)
systemctl enable "uwsgi@${CONF%.*}"
mkdir -p "${uWSGI_APPS_ENABLED}"
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
ln -s "${uWSGI_APPS_AVAILABLE}/${CONF}" "${uWSGI_APPS_ENABLED}/${CONF}"
info_msg "enabled uWSGI app: ${CONF} (restart required)"
;;
fedora-*)
mkdir -p "${uWSGI_APPS_ENABLED}"
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
ln -s "${uWSGI_APPS_AVAILABLE}/${CONF}" "${uWSGI_APPS_ENABLED}/${CONF}"
chown "${uWSGI_USER}:${uWSGI_GROUP}" "${uWSGI_APPS_ENABLED}/${CONF}"
info_msg "enabled uWSGI app: ${CONF}"
;;
*)
# FIXME
@ -843,7 +889,7 @@ uWSGI_disable_app() {
local CONF="$1"
if [[ -z $CONF ]]; then
err_msg "uWSGI_enable_app: missing arguments"
err_msg "uWSGI_disable_app: missing arguments"
return 42
fi
@ -856,6 +902,11 @@ uWSGI_disable_app() {
arch-*)
systemctl stop "uwsgi@${CONF%.*}"
systemctl disable "uwsgi@${CONF%.*}"
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
;;
fedora-*)
# in emperor mode, just remove the app.ini file
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
;;
*)
# FIXME

View file

@ -344,7 +344,7 @@ add_subordinate_ids() {
del_subordinate_ids() {
local out
local exit_value
local exit_val
if grep "root:${HOST_USER_ID}:1" /etc/subuid -qs; then
# TODO: root user is always in use by process 1, how can we remove subordinates?
info_msg "remove lxd permission to map ${HOST_USER_ID}'s user/group id through"

View file

@ -96,6 +96,11 @@ To activate morty in searx, add result_proxy to your settings.yml::
result_proxy:
url : ${PUBLIC_URL_MORTY}/
server:
...
image_proxy : True # Proxying image results through searx
...
further read: ${DOCS_URL}/admin/morty.html
EOF

View file

@ -43,6 +43,9 @@ case $DIST_ID in
git build-essential libxslt-dev zlib1g-dev libffi-dev libssl-dev "
;;
arch) # pacman packages
# FIXME:
# - /usr/lib/uwsgi/http_plugin.so: cannot open shared object file: No such file or directory !!!
# - /usr/lib/uwsgi/systemd_logger_plugin.so: cannot open shared object file: No such file or directory !!!
SEARX_PACKAGES="\
python python-pip python-lxml python-babel \
uwsgi uwsgi-plugin-python \

View file

@ -0,0 +1,66 @@
[uwsgi]
# uWSGI core
# ----------
#
# https://uwsgi-docs.readthedocs.io/en/latest/Options.html#uwsgi-core
# Who will run the code
uid = ${SERVICE_USER}
gid = ${SERVICE_GROUP}
# chdir to specified directory before apps loading
chdir = ${SEARX_SRC}/searx
# searx configuration (settings.yml)
env = SEARX_SETTINGS_PATH=${SEARX_SETTINGS_PATH}
# disable logging for privacy
logger = systemd
disable-logging = false
# The right granted on the created socket
chmod-socket = 666
# Plugin to use and interpretor config
single-interpreter = true
# enable master process
master = true
# load apps in each worker instead of the master
lazy-apps = true
# load uWSGI plugins
plugin = python,http,systemd_logger
# By default the Python plugin does not initialize the GIL. This means your
# app-generated threads will not run. If you need threads, remember to enable
# them with enable-threads. Running uWSGI in multithreading mode (with the
# threads options) will automatically enable threading support. This *strange*
# default behaviour is for performance reasons.
enable-threads = true
# plugin: python
# --------------
#
# https://uwsgi-docs.readthedocs.io/en/latest/Options.html#plugin-python
# load a WSGI module
module = searx.webapp
# set PYTHONHOME/virtualenv
virtualenv = ${SEARX_PYENV}
# add directory (or glob) to pythonpath
pythonpath = ${SEARX_SRC}
# plugin http
# -----------
#
# https://uwsgi-docs.readthedocs.io/en/latest/Options.html#plugin-http
# Native HTTP support: https://uwsgi-docs.readthedocs.io/en/latest/HTTP.html
http = ${SEARX_INTERNAL_URL}