aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2020-12-09 20:30:40 -0500
committerB Stack <bgstack15@gmail.com>2020-12-09 20:30:40 -0500
commit260c70e3173f3595fa183612c8641c6da36de572 (patch)
tree150f97296c0ee28bc846c3a81ce124186901c38b
parentadd some example files, and experimental logging (diff)
downloadhex-zero-260c70e3173f3595fa183612c8641c6da36de572.tar.gz
hex-zero-260c70e3173f3595fa183612c8641c6da36de572.tar.bz2
hex-zero-260c70e3173f3595fa183612c8641c6da36de572.zip
use uwsgi!
apparently uwsgi_python3 is the useful binary in Devuan
-rw-r--r--config/hex-zero.etc.default7
-rwxr-xr-xconfig/hex-zero.init (renamed from config/hex-zero)34
-rwxr-xr-xhex-zero.py6
-rwxr-xr-xhex-zero.wsgi19
4 files changed, 45 insertions, 21 deletions
diff --git a/config/hex-zero.etc.default b/config/hex-zero.etc.default
new file mode 100644
index 0000000..c8d8da7
--- /dev/null
+++ b/config/hex-zero.etc.default
@@ -0,0 +1,7 @@
+export UWSGI_USER=hex-zero
+export UWSGI_BIN=/usr/bin/uwsgi_python3
+export LISTEN_HOST=localhost
+export LISTEN_PORT=3031
+export PIDFILE=/run/hex-zero.pid
+export LOGFILE=/var/log/hex-zero/hex-zero.log
+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}"
diff --git a/config/hex-zero b/config/hex-zero.init
index 1d79d18..17bac95 100755
--- a/config/hex-zero
+++ b/config/hex-zero.init
@@ -17,9 +17,9 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="hex-zero"
NAME=hex-zero
-DAEMON=/var/www/0x0/hex-zero.py
-DAEMON_ARGS="runserver"
-PIDFILE=/var/run/$NAME.pid
+DAEMON=/var/www/0x0/hex-zero.wsgi
+DAEMON_ARGS=""
+PIDFILE=/tmp/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
USER=hex-zero
@@ -46,19 +46,20 @@ do_start()
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
- start-stop-daemon --start --quiet --chuid $USER --group $USER --make-pidfile --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
- || return 1
- start-stop-daemon --start --quiet --chuid $USER --group $USER --background --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- \
- $DAEMON_ARGS \
- || return 2
- # The above code will not work for interpreted scripts, use the next
- # six lines below instead (Ref: #643337, start-stop-daemon(8) )
- #start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \
- # --name $NAME --test > /dev/null \
+ #start-stop-daemon --start --quiet --chuid $USER --group $USER --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
# || return 1
- #start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \
- # --name $NAME -- $DAEMON_ARGS \
+ #start-stop-daemon --start --quiet --chuid $USER --group $USER --background --pidfile $PIDFILE --exec $DAEMON -- \
+ # $DAEMON_ARGS \
# || return 2
+ #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) )
+ start-stop-daemon --start --chuid $USER --pidfile $PIDFILE --startas $DAEMON \
+ --name uwsgi_python3 --test > /dev/null \
+ || return 1
+ start-stop-daemon --start --chuid $USER --background --pidfile $PIDFILE --startas $DAEMON \
+ --name uwsgi_python3 -- $DAEMON_ARGS \
+ || return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
@@ -75,7 +76,8 @@ do_stop()
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
- start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $USER --pidfile $PIDFILE
+ #start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user $USER --pidfile $PIDFILE
+ /usr/bin/uwsgi_python3 --stop $PIDFILE 2>/dev/null
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
@@ -100,7 +102,7 @@ do_reload() {
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
- start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+ start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name uwsgi_python3
return 0
}
diff --git a/hex-zero.py b/hex-zero.py
index a93ebe0..81c8169 100755
--- a/hex-zero.py
+++ b/hex-zero.py
@@ -312,7 +312,6 @@ def store_url(url, addr):
@app.route("/<path:path>")
def get(path):
- app.logger.info("next source: {0}".format(str(request.environ["HTTP_X_FORWARDED_FOR"])))
p = os.path.splitext(path)
id = su.debase(p[0])
@@ -349,7 +348,6 @@ def get(path):
@app.route("/dump_files/")
@app.route("/dump_files/<int:start>")
def dump_files(start=0):
- app.logger.info("next source: {0}".format(str(request.environ["HTTP_X_FORWARDED_FOR"])))
meta = "#FORMAT: BEACON\n#PREFIX: {}/\n\n".format(fhost_url("https"))
def gen():
@@ -363,7 +361,6 @@ def dump_files(start=0):
@app.route("/dump_urls/")
@app.route("/dump_urls/<int:start>")
def dump_urls(start=0):
- app.logger.info("next source: {0}".format(str(request.environ["HTTP_X_FORWARDED_FOR"])))
meta = "#FORMAT: BEACON\n#PREFIX: {}/\n\n".format(fhost_url("https"))
def gen():
@@ -381,7 +378,6 @@ def dump_urls(start=0):
@app.route("/", methods=["GET", "POST"])
def fhost():
- app.logger.info("next source: {0}".format(str(request.environ["HTTP_X_FORWARDED_FOR"])))
if request.method == "POST":
out = None
@@ -397,6 +393,7 @@ def fhost():
out = shorten(request.form["shorten"])
if not out == None:
+ app.logger.info("Stored file: "+str(out.strip()))
return Response(out, mimetype="text/plain")
abort(400)
@@ -422,7 +419,6 @@ def fhost():
@app.route("/robots.txt")
def robots():
- app.logger.info("next source: {0}".format(str(request.environ["HTTP_X_FORWARDED_FOR"])))
return """User-agent: *
Disallow: /
"""
diff --git a/hex-zero.wsgi b/hex-zero.wsgi
new file mode 100755
index 0000000..7f10e20
--- /dev/null
+++ b/hex-zero.wsgi
@@ -0,0 +1,19 @@
+#!/bin/sh
+test -f /etc/default/hex-zero && . /etc/default/hex-zero
+test -z "${UWSGI_USER}" && export UWSGI_USER=hex-zero
+test -z "${UWSGI_BIN}" && export UWSGI_BIN=/usr/bin/uwsgi_python3
+test -z "${LISTEN_HOST}" && export LISTEN_HOST=localhost
+test -z "${LISTEN_PORT}" && export LISTEN_PORT=3031
+test -z "${PIDFILE}" && export PIDFILE=/tmp/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}"
+
+#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 "${UWSGI_USER}" != "${USER}" && {
+# printf "Please run $0 as user UWSGI_USER (${UWSGI_USER}) and not $USER. Aborted.\n" 1>&2 ; exit 1 ;
+#}
+
+${UWSGI_BIN} ${UWSGI_OPTS}
bgstack15