diff options
-rwxr-xr-x | check-for-short_url.sh | 17 | ||||
-rwxr-xr-x | config/hex-zero.init | 8 | ||||
-rwxr-xr-x | hex-zero.wsgi | 13 |
3 files changed, 33 insertions, 5 deletions
diff --git a/check-for-short_url.sh b/check-for-short_url.sh new file mode 100755 index 0000000..7d37d37 --- /dev/null +++ b/check-for-short_url.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# This script exists because Debian does not package short_url in a dpkg +test -r /etc/default/hex-zero && . /etc/default/hex-zero + +# check global python for short_url +echo "import short_url" | $( which python3 2>/dev/null ) 2>/dev/null && exit 0 # short-circuit if we find it + +# So if we get here, it was not installed globally, +# so we need to check the configured user, if we are not that user already. +test "${UWSGI_USER}" != "${USER}" && { + echo "Will attempt to switch user to ${UWSGI_USER} and check for short_url." 1>&2 + echo "import short_url" | sudo su "${UWSGI_USER}" -c "$( which python3 2>/dev/null ) 2>/dev/null" && exit 0 # short-circuit if we find it +} + +echo "Please run something similar to the following, before running hex-zero:" +echo "sudo su ${UWSGI_USER} -c 'pip3 --user install short_url'" +exit 1 diff --git a/config/hex-zero.init b/config/hex-zero.init index 18dbf60..46bb29c 100755 --- a/config/hex-zero.init +++ b/config/hex-zero.init @@ -54,6 +54,14 @@ do_start() #su $USER -c "$DAEMON" & # The above code will not work for interpreted scripts, use the next # six lines below instead (Ref: #643337, start-stop-daemon(8) ) + test -r /var/www/0x0/check-for-short_url.sh && { + /bin/sh /var/www/0x0/check-for-short_url.sh || { + # the init script is somehow prevent all displayed output even when directly outputing it to /dev/pts/3 + echo "Please run something similar to the following, before running hex-zero:" + echo "sudo su ${USER} -c 'pip3 --user install short_url'" + exit 1 + } + } start-stop-daemon --start --pidfile $PIDFILE --startas $DAEMON \ --name uwsgi_python3 --test > /dev/null \ || return 1 diff --git a/hex-zero.wsgi b/hex-zero.wsgi index d3979ee..c3f7747 100755 --- a/hex-zero.wsgi +++ b/hex-zero.wsgi @@ -8,12 +8,15 @@ test -z "${PIDFILE}" && export PIDFILE=/var/run/hex-zero.pid test -z "${LOGFILE}" && export LOGFILE=/var/log/hex-zero/hex-zero.log test -z "${UWSGI_OPTS}" && export UWSGI_OPTS="--http-socket ${LISTEN_HOST}:${LISTEN_PORT} --wsgi-file /var/www/0x0/hex-zero.py --callable app --log-x-forwarded-for --logto ${LOGFILE} --touch-reload /var/www/0x0/hex-zero.py --touch-reload /var/www/0x0/hex-zero.conf --pidfile ${PIDFILE} --uid ${UWSGI_USER}" -#test -n "${FORCE_KILL_OLD_UWSGI}" && { -# ps -o user=,pid=,command:80= -u "${UWSGI_USER}" | awk '/hex-zero\.py/{print $2}' | xargs --no-run-if-empty kill -#} +# check for short_url +/var/www/0x0/check-for-short_url.sh || exit 1 -test "${USER}" != "root" && test -n "${USER}" && { - printf "Please run $0 as user root. It will downgrade permissions when running uwsgi. Aborted.\n" 1>&2 ; exit 1 ; +test -n "${FORCE_KILL_OLD_UWSGI}" && { + ps -o user=,pid=,command:80= -u "${UWSGI_USER}" | awk '/hex-zero\.py/{print $2}' | xargs --no-run-if-empty kill +} + +test "${USER}" != "root" && test "${USER}" != "${UWSGI_USER}" && test -n "${USER}" && { + printf "Please run $0 as user root instead of ${USER}. It will downgrade permissions when running uwsgi. Aborted.\n" 1>&2 ; exit 1 ; } ${UWSGI_BIN} ${UWSGI_OPTS} |