From a321b5423a8f151692060219d3b39c07d1f8126e Mon Sep 17 00:00:00 2001 From: Stanislaw Wawszczak Date: Thu, 9 Feb 2023 23:36:04 +0100 Subject: [PATCH 1/3] Added new volume to Dockerfile Created symlinks for mbconfig.cfg and persistent.file --- Dockerfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2ad2a0b5..3bf5bfe8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,11 @@ FROM debian:bullseye-20211201 - COPY . /workdir WORKDIR /workdir +RUN mkdir /persistent +VOLUME /persistent RUN ./install.sh docker +RUN touch /persistent/mbconfig.cfg +RUN ln -s /persistent/mbconfig.cfg /workdir/webserver/mbconfig.cfg +RUN touch /persistent/persistent.file +RUN ln -s /persistent/persistent.file /workdir/webserver/persistent.file ENTRYPOINT ["./start_openplc.sh"] From 4fb51f96da6c7960100ffd7bf5d4a9ca380a4c0a Mon Sep 17 00:00:00 2001 From: Stanislaw Wawszczak Date: Fri, 10 Feb 2023 12:41:06 +0100 Subject: [PATCH 2/3] adding persistence in Docker volume feature symlinks for: openplc.db persistent.file mbconfig.cfg dnp3.cfg st_files /persistent -> /workdir/webserver paths are hardcoded in scripts/start_openplc.sh --- Dockerfile | 13 ++++++++++++- webserver/scripts/start_openplc.sh | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3bf5bfe8..363c4c86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,18 @@ RUN mkdir /persistent VOLUME /persistent RUN ./install.sh docker RUN touch /persistent/mbconfig.cfg -RUN ln -s /persistent/mbconfig.cfg /workdir/webserver/mbconfig.cfg RUN touch /persistent/persistent.file +RUN mkdir /persistent/st_files +RUN cp /workdir/webserver/openplc.db /persistent/openplc.db +RUN mv /workdir/webserver/openplc.db /workdir/webserver/openplc_default.db +RUN cp /workdir/webserver/dnp3.cfg /persistent/dnp3.cfg +RUN mv /workdir/webserver/dnp3.cfg /workdir/webserver/dnp3_default.cfg +RUN cp /workdir/webserver/st_files/* /persistent/st_files +run mv /workdir/webserver/st_files /workdir/webserver/st_files_default +RUN ln -s /persistent/mbconfig.cfg /workdir/webserver/mbconfig.cfg RUN ln -s /persistent/persistent.file /workdir/webserver/persistent.file +RUN ln -s /persistent/openplc.db /workdir/webserver/openplc.db +RUN ln -s /persistent/dnp3.cfg /workdir/webserver/dnp3.cfg +RUN ln -s /persistent/st_files /workdir/webserver/st_files + ENTRYPOINT ["./start_openplc.sh"] diff --git a/webserver/scripts/start_openplc.sh b/webserver/scripts/start_openplc.sh index dd276ac5..794ce9c2 100755 --- a/webserver/scripts/start_openplc.sh +++ b/webserver/scripts/start_openplc.sh @@ -1,3 +1,24 @@ #!/bin/bash +if [[ ! -f "/persistent/dnp3.cfg" ]] +then + cp /workdir/webserver/dnp3_default.cfg /persistent/dnp3.cfg +fi +if [[ ! -f "/persistent/openplc.db" ]] +then + cp /workdir/webserver/openplc_default.db /persistent/openplc.db +fi +if [[ ! -d "/persistent/st_files" ]] +then + mkdir /persistent/st_files + cp /workdir/webserver/st_files_default/* /persistent/st_files +fi +if [[ ! -f "/persistent/persistent.file" ]] +then + touch /persistent/persistent.file +fi +if [[ ! -f "/persistent/mbconfig.cfg" ]] +then + touch /persistent/mbconfig.cfg +fi cd webserver python2.7 webserver.py From e15cde4c8d03a809be938849ef85eef1ef7b5c3d Mon Sep 17 00:00:00 2001 From: Stanislaw Wawszczak Date: Fri, 10 Feb 2023 21:06:26 +0100 Subject: [PATCH 3/3] added check and automatic creation of /persistent directory during startup of OpenPlc This allows to startup in the same way inside and outside of Docker environment. In docker container it is mount point for volume. Outside docker, ie. normal linux it will persist all data in /persistent directory --- webserver/scripts/start_openplc.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webserver/scripts/start_openplc.sh b/webserver/scripts/start_openplc.sh index 794ce9c2..9a5bbcc7 100755 --- a/webserver/scripts/start_openplc.sh +++ b/webserver/scripts/start_openplc.sh @@ -1,4 +1,8 @@ #!/bin/bash +if [[ ! -d "/persistent" ]] +then + mkdir /persistent +fi if [[ ! -f "/persistent/dnp3.cfg" ]] then cp /workdir/webserver/dnp3_default.cfg /persistent/dnp3.cfg