From 19338ba8d5d37b11b901ab577bd6431836541d93 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Fri, 13 Nov 2020 15:01:53 +0100
Subject: [PATCH] Add daemon loop
---
.env.tpl | 4 ++++
web/Dockerfile | 1 -
web/app/models.py | 2 +-
web/boot.sh | 29 +++++++++++++++++------------
web/nopaque-daemon.sh | 7 +++++++
5 files changed, 29 insertions(+), 14 deletions(-)
create mode 100755 web/nopaque-daemon.sh
diff --git a/.env.tpl b/.env.tpl
index e7c2cea7..ee8a68af 100644
--- a/.env.tpl
+++ b/.env.tpl
@@ -111,6 +111,10 @@ NOPAQUE_ADMIN=
# Swarm nodes
# NOPAQUE_DATA_DIR=
+# CHOOSE ONE: False, True
+# DEFAULT: False
+# NOPAQUE_DAEMON_ENABLED=
+
# DEFAULT: 0.0.0.0
# NOPAQUE_HOST=
diff --git a/web/Dockerfile b/web/Dockerfile
index 3681b701..d5de0392 100644
--- a/web/Dockerfile
+++ b/web/Dockerfile
@@ -17,7 +17,6 @@ RUN apt-get update \
&& apt-get install --no-install-recommends --yes \
build-essential \
libpq-dev \
- wait-for-it \
&& rm -r /var/lib/apt/lists/*
diff --git a/web/app/models.py b/web/app/models.py
index fc12610d..e912bf17 100644
--- a/web/app/models.py
+++ b/web/app/models.py
@@ -35,7 +35,7 @@ class Role(db.Model):
# Fields
default = db.Column(db.Boolean, default=False, index=True)
name = db.Column(db.String(64), unique=True)
- permissions = db.Column(db.BigInteger)
+ permissions = db.Column(db.Integer)
# Relationships
users = db.relationship('User', backref='role', lazy='dynamic')
diff --git a/web/boot.sh b/web/boot.sh
index 9c87cfd1..d6536518 100755
--- a/web/boot.sh
+++ b/web/boot.sh
@@ -1,21 +1,26 @@
#!/bin/bash
+
+if [[ "${NOPAQUE_DAEMON_ENABLED}" == "True" ]]; then
+ echo "Starting nopaque daemon..."
+ ./nopaque-daemon.sh &
+fi
+
source venv/bin/activate
-while true; do
- flask deploy
- if [[ "$?" == "0" ]]; then
- break
- fi
- echo Deploy command failed, retrying in 5 secs...
- sleep 5
-done
-
-if [[ "$#" -eq 0 ]]; then
+if [[ "${#}" -eq 0 ]]; then
+ while true; do
+ flask deploy
+ if [[ "${?}" == "0" ]]; then
+ break
+ fi
+ echo Deploy command failed, retrying in 5 secs...
+ sleep 5
+ done
python nopaque.py
-elif [[ "$1" == "flask" ]]; then
+elif [[ "${1}" == "flask" ]]; then
exec ${@:1}
else
- echo "$0 [COMMAND]"
+ echo "${0} [COMMAND]"
echo ""
echo "nopaque startup script"
echo ""
diff --git a/web/nopaque-daemon.sh b/web/nopaque-daemon.sh
new file mode 100755
index 00000000..7a903646
--- /dev/null
+++ b/web/nopaque-daemon.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+source venv/bin/activate
+
+while true; do
+ flask tasks
+ sleep 10
+done