diff --git a/base/app/app.py b/base/app/app.py index 471a97d..df08413 100644 --- a/base/app/app.py +++ b/base/app/app.py @@ -13,20 +13,22 @@ import petname from flask import Flask, jsonify -state_base = "/var/lib/private/orijen-udf-base/" +state_base = "/var/lib/state/" def run_flask(app): """Function to run the Flask app on a separate thread.""" app.run(host='0.0.0.0', port=5123) def save_state(file, state): + """Save state to a file.""" os.makedirs(os.path.dirname(state_base + file), exist_ok=True) - with open(state_base + file, 'w') as f: + with open(state_base + file, 'w', encoding="utf-8") as f: f.write(state) def load_state(file): + """Load state from a file.""" try: - with open(state_base + file, 'r') as f: + with open(state_base + file, 'r', encoding="utf-8") as f: return json.load(f) except FileNotFoundError: return {} diff --git a/orijen-udf-base-install.sh b/orijen-udf-base-install.sh index 8792ced..0743791 100755 --- a/orijen-udf-base-install.sh +++ b/orijen-udf-base-install.sh @@ -35,7 +35,7 @@ Restart=always ExecStartPre=-/usr/bin/docker stop $CONTAINER ExecStartPre=-/usr/bin/docker rm $CONTAINER ExecStartPre=/usr/bin/docker pull $IMAGE -ExecStart=/usr/bin/docker run -p 5123:5123 --rm --name $CONTAINER $IMAGE +ExecStart=/usr/bin/docker run -p 5123:5123 -v $CONTAINER:/var/lib/state --rm --name $CONTAINER $IMAGE ExecStop=/usr/bin/docker stop $CONTAINER StateDirectory=$CONTAINER