diff --git a/.github/workflows/linux-docker-build.yml b/.github/workflows/linux-docker-build.yml index e2f26081b..0dc006fe0 100644 --- a/.github/workflows/linux-docker-build.yml +++ b/.github/workflows/linux-docker-build.yml @@ -3,7 +3,6 @@ on: # but only for the main branch push: branches: - - master # pull_request: jobs: Build-Docker-Image: @@ -64,24 +63,24 @@ jobs: mkdir -p ~/terminology/fhir-server wget -q --no-clobber https://storage.googleapis.com/ig-build/snomed.test.cache -O ~/terminology/fhir-server/snomed.test.cache || true ls ~/terminology/fhir-server/snomed.test.cache - - name: Run tests in docker +# - name: Run tests in docker +# run: | +# docker images --all +# docker run \ +# --network gh \ +# -v ~/terminology:/terminology \ +# -v ~/test-settings.ini:/work/fhirserver/exec/64/test-settings.ini \ +# fhirserver -tests + + - name: Tag and push Docker image run: | - docker images --all - docker run \ - --network gh \ - -v ~/terminology:/terminology \ - -v ~/test-settings.ini:/work/fhirserver/exec/64/test-settings.ini \ - fhirserver -tests + # Extract the FHIR server version from the library/version.inc file + FHIR_VERSION=$(grep -oP "FHIR_CODE_FULL_VERSION = '\K[^']+" library/version.inc) -# - name: Tag and push Docker image -# run: | -# # Extract the FHIR server version from the library/version.inc file -# FHIR_VERSION=$(grep -oP "FHIR_CODE_FULL_VERSION = '\K[^']+" library/version.inc) -# -# # Tag the Docker image with the extracted version and "latest" -# docker tag fhirserver ${{ secrets.DOCKERHUB_USERNAME }}/fhirserver:$FHIR_VERSION -# docker tag fhirserver ${{ secrets.DOCKERHUB_USERNAME }}/fhirserver:latest -# -# # Push both tagged images to Docker Hub -# docker push ${{ secrets.DOCKERHUB_USERNAME }}/fhirserver:$FHIR_VERSION -# docker push ${{ secrets.DOCKERHUB_USERNAME }}/fhirserver:latest + # Tag the Docker image with the extracted version and "latest" + docker tag fhirserver ${{ secrets.DOCKERHUB_USERNAME }}/fhirserver:$FHIR_VERSION + docker tag fhirserver ${{ secrets.DOCKERHUB_USERNAME }}/fhirserver:latest + + # Push both tagged images to Docker Hub + docker push ${{ secrets.DOCKERHUB_USERNAME }}/fhirserver:$FHIR_VERSION + docker push ${{ secrets.DOCKERHUB_USERNAME }}/fhirserver:latest diff --git a/Dockerfile b/Dockerfile index c04ad593b..2c275e098 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ -FROM ubuntu:22.04 as builder +FROM ubuntu:24.04 AS builder ENV DEBIAN_FRONTEND=noninteractive -RUN apt update && apt install -y tzdata wget git unixodbc-dev libgtk2.0-dev xvfb sqlite3 libsqlite3-dev build-essential curl +RUN apt update && apt-get upgrade -y && apt install -y tzdata wget git unixodbc-dev libgtk2.0-dev xvfb sqlite3 libsqlite3-dev build-essential curl binutils && apt-get clean && rm -rf /var/lib/apt/lists/* # Download and build OpenSSL 1.1.1w WORKDIR /tmp @@ -15,7 +15,7 @@ RUN wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz \ && make test \ && make install -RUN ls -la /usr/local/lib/ +# RUN ls -la /usr/local/lib/ # Set the timezone RUN echo "UTC" > /etc/timezone @@ -36,40 +36,126 @@ RUN /work/bootstrap/linux-toolchain.sh /work/bootstrap WORKDIR /work/fhirserver COPY . /work/fhirserver -RUN /work/bootstrap/linux-libraries.sh /work/bootstrap -RUN cp /usr/local/lib/*.so* /usr/lib/ -RUN /work/fhirserver/build/linux-fhirserver.sh /work/bootstrap -RUN cp exec/pack/*.properties exec/64 +RUN /work/bootstrap/linux-libraries.sh /work/bootstrap && \ + cp /usr/local/lib/*.so* /usr/lib/ && \ + /work/fhirserver/build/linux-fhirserver.sh /work/bootstrap && \ + cp exec/pack/*.properties exec/64 +# RUN cp exec/install/* exec/64 + +RUN mkdir -p /work/fhirserver/exec/install/bin && \ + mkdir -p /work/fhirserver/exec/install/x86_64 && \ + mkdir -p /work/fhirserver/exec/install/content && \ + mkdir -p /work/fhirserver/exec/install/config && \ + # mkdir -p /work/fhirserver/exec/install/config/config && \ + mkdir -p /work/fhirserver/exec/install/default_config && \ + mkdir -p /work/fhirserver/exec/install/web + +RUN cd /work/fhirserver && \ + cp /work/fhirserver/exec/64/fhirserver /work/fhirserver/exec/install/bin && \ + cp /work/fhirserver/exec/64/FHIRToolkit /work/fhirserver/exec/install/bin && \ + cp /work/fhirserver/exec/64/FHIRConsole /work/fhirserver/exec/install/bin && \ + cp /work/fhirserver/exec/pack/linux/*so* /work/fhirserver/exec/install/x86_64 + +RUN cp /work/fhirserver/exec/pack/linux/start.sh /work/fhirserver/exec/install/bin/start.sh && \ + cp /work/fhirserver/exec/pack/linux/install.sh /work/fhirserver/exec/install && \ + cp /work/fhirserver/exec/pack/linux/get-openssl.sh /work/fhirserver/exec/install && \ + cp /tmp/openssl-1.1.1w/*.so* /work/fhirserver/exec/install/x86_64 && \ + cp /work/fhirserver/exec/pack/*.properties /work/fhirserver/exec/install/content && \ + cp /work/fhirserver/exec/pack/*.dat /work/fhirserver/exec/install/content && \ + + cp /work/fhirserver/exec/pack/fhirserver.cfg /work/fhirserver/exec/install/config && \ + cp /work/fhirserver/exec/pack/web.ini /work/fhirserver/exec/install/config && \ + + + cp /work/fhirserver/exec/pack/web.ini /work/fhirserver/exec/install/default_config && \ + cp /work/fhirserver/exec/pack/fhirserver.cfg /work/fhirserver/exec/install/default_config && \ + cp /work/fhirserver/config/config.ini /work/fhirserver/exec/install/default_config/config.ini && \ + cp /work/fhirserver/config/config.json /work/fhirserver/exec/install/default_config/config.json && \ + # cp /work/fhirserver/config/config.ini /work/fhirserver/exec/install/config/config.ini && \ + + # cp /work/fhirserver/config/config_bare.json /work/fhirserver/exec/install/default_config/config.json && \ + # cp /work/fhirserver/config/config.ini /work/fhirserver/exec/install/config/default_config && \ + + mkdir -p /work/fhirserver/exec/install/web && \ + cp -r /work/fhirserver/server/web/* /work/fhirserver/exec/install/web && \ + cd /work/fhirserver/exec && tar -czvf ./install.tgz ./install/ && ls -la /work/fhirserver/exec + # Set the health check -HEALTHCHECK --interval=1m --timeout=10s --retries=5 \ +HEALTHCHECK --interval=1m --timeout=10s --retries=5 \ CMD curl -f http://localhost:${PORT}/fhir/metadata || exit 1 # Set the environment variables -ENV DISPLAY :99 -ENV PORT 80 -ENV TERMINOLOGY_CACHE /terminology +ENV DISPLAY=:99 +ENV PORT=80 +ENV TERMINOLOGY_CACHE=/terminology VOLUME /terminology ENV DEBIAN_FRONTEND= -RUN printf '#!/bin/bash \n\ - set -e \n\ - start_xvfb() { \n\ - Xvfb :99 -screen 0 1024x768x8 -nolisten tcp & \n\ - } \n\ - stop_xvfb() { \n\ - killall Xvfb || true \n\ - } \n\ - trap stop_xvfb SIGTERM \n\ - rm -f /tmp/.X99-lock \n\ - start_xvfb \n\ - echo "[web]" > /work/fhirserver/exec/64/web.ini; \n\ - echo "http=${PORT}" >> /work/fhirserver/exec/64/web.ini; \n\ - /work/fhirserver/exec/64/fhirserver $(eval echo "$@")' > /bin/entrypoint.sh && \ - chmod +x /bin/entrypoint.sh - - -ENTRYPOINT ["/bin/entrypoint.sh"] - -CMD ["-cmd", "exec", "-cfg", "/config/config.ini", "-local", "$TERMINOLOGY_CACHE"] +# ENTRYPOINT ["/bin/entrypoint.sh"] + +# CMD ["-cmd", "exec", "-cfg", "/config/config.ini", "-local", "$TERMINOLOGY_CACHE"] + + + +# Runtime stage +FROM ubuntu:24.04 AS runtime + +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=UTC +# Set up environment variables +# ENV HOME=~/ +ENV DISPLAY=:99 +ENV PORT=80 +ENV TERMINOLOGY_CACHE=/var/cache/txcache + +# Install runtime dependencies +RUN apt-get update && apt-get upgrade -y && apt-get install -y wget tzdata xvfb libgtk2.0-0 libsqlite3-dev curl && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && mkdir -p $HOME/fhirserver/config $TERMINOLOGY_CACHE /fhirserver \ + && chmod -R 777 $TERMINOLOGY_CACHE \ + && chmod -R 777 /fhirserver + +# Copy necessary files from the builder stage +COPY --from=builder /work/fhirserver/exec/install.tgz /fhirserver/install.tgz + +# RUN cd /fhirserver \ +# && tar -xzvf install.tgz \ +# && cd ./install \ +# && ./install.sh > install.log 2>&1 + +# Assuming /fhirserver is your working directory +WORKDIR /fhirserver + +# Extract the contents of the tar file +RUN tar -xzvf install.tgz + +# Change working directory to the extracted folder +WORKDIR /fhirserver/install + + +### Choose your flavour / uncomment one of the following lines ###: +## +## + +# 1. Run the installation script for a blank, clean install +RUN chmod a+x ./install.sh && ./install.sh + +# OR + +# 2. Run the installation script With Zero Config as tx.fhir.org +# RUN chmod a+x ./install.sh && ./install.sh -nodaemon -zero=https://storage.googleapis.com/tx-fhir-org/config.json + +## +## +## +#################################################################### + +WORKDIR /root/fhirserver + +# Define entrypoint and command +CMD ["bash", "-c", "cd ~/fhirserver/ && ./start.sh"] + +# Expose the necessary port +EXPOSE 80 diff --git a/Dockerfile prev b/Dockerfile prev new file mode 100644 index 000000000..5a2816485 --- /dev/null +++ b/Dockerfile prev @@ -0,0 +1,152 @@ +FROM ubuntu:22.04 as builder + +ENV DEBIAN_FRONTEND=noninteractive + + +RUN apt update && apt install -y tzdata wget git unixodbc-dev libgtk2.0-dev xvfb sqlite3 libsqlite3-dev build-essential curl binutils + +# Download and build OpenSSL 1.1.1w +WORKDIR /tmp +RUN wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz \ + && tar -xf openssl-1.1.1w.tar.gz \ + && cd openssl-1.1.1w \ + && ./config \ + && make \ + && make test \ + && make install + +RUN ls -la /usr/local/lib/ + +# Set the timezone +RUN echo "UTC" > /etc/timezone + +RUN cd /tmp && \ + wget https://dev.mysql.com/get/Downloads/Connector-ODBC/8.0/mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit.tar.gz && \ + tar -xzvf mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit.tar.gz && \ + cp -r mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit/lib/* /usr/local/lib && \ + cp -r mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit/bin/* /usr/local/bin && \ + rm -rf mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit && \ + rm -rf mysql-connector-odbc-8.0.26-linux-glibc2.12-x86-64bit.tar.gz && \ + myodbc-installer -a -d -n "MySQL ODBC 8.0 Driver" -t "Driver=/usr/local/lib/libmyodbc8w.so" && \ + myodbc-installer -a -d -n "MySQL ODBC 8.0" -t "Driver=/usr/local/lib/libmyodbc8a.so" + +COPY build/linux-toolchain.sh build/linux-libraries.sh /work/bootstrap/ +RUN /work/bootstrap/linux-toolchain.sh /work/bootstrap + +WORKDIR /work/fhirserver +COPY . /work/fhirserver + +RUN /work/bootstrap/linux-libraries.sh /work/bootstrap +RUN cp /usr/local/lib/*.so* /usr/lib/ +RUN /work/fhirserver/build/linux-fhirserver.sh /work/bootstrap +RUN cp exec/pack/*.properties exec/64 +# RUN cp exec/install/* exec/64 + +RUN mkdir -p /work/fhirserver/exec/install/bin +RUN mkdir -p /work/fhirserver/exec/install/x86_64 +RUN mkdir -p /work/fhirserver/exec/install/content +RUN mkdir -p /work/fhirserver/exec/install/config +RUN mkdir -p /work/fhirserver/exec/install/config/config +RUN mkdir -p /work/fhirserver/exec/install/web + +RUN cd /work/fhirserver +RUN cp /work/fhirserver/exec/64/fhirserver /work/fhirserver/exec/install/bin +RUN cp /work/fhirserver/exec/64/FHIRToolkit /work/fhirserver/exec/install/bin +RUN cp /work/fhirserver/exec/64/FHIRConsole /work/fhirserver/exec/install/bin +RUN cp /work/fhirserver/exec/pack/linux/*so* /work/fhirserver/exec/install/x86_64 +RUN cp /work/fhirserver/exec/pack/linux/start.sh /work/fhirserver/exec/install/bin +RUN cp /work/fhirserver/exec/pack/linux/install.sh /work/fhirserver/exec/install +RUN cp /work/fhirserver/exec/pack/linux/get-openssl.sh /work/fhirserver/exec/install +RUN cp /tmp/openssl-1.1.1w/*.so* /work/fhirserver/exec/install/x86_64 +RUN cp /work/fhirserver/exec/pack/*.properties /work/fhirserver/exec/install/content +RUN cp /work/fhirserver/exec/pack/*.dat /work/fhirserver/exec/install/content +RUN cp /work/fhirserver/exec/pack/fhirserver.cfg /work/fhirserver/exec/install/config +RUN cp /work/fhirserver/exec/64/web.ini /work/fhirserver/exec/install/config +RUN cp /work/fhirserver/config/config.ini /work/fhirserver/exec/install/config/config +RUN mkdir -p /work/fhirserver/exec/install/web +RUN cp -r /work/fhirserver/server/web/* /work/fhirserver/exec/install/web + +RUN cd /work/fhirserver/exec && tar -czvf ./install.tgz ./install/ && ls -la /work/fhirserver/exec + + +# Set the health check +HEALTHCHECK --interval=1m --timeout=10s --retries=5 \ + CMD curl -f http://localhost:${PORT}/fhir/metadata || exit 1 + +# Set the environment variables +ENV DISPLAY :99 +ENV PORT 80 +ENV TERMINOLOGY_CACHE /terminology +VOLUME /terminology + +ENV DEBIAN_FRONTEND= + +RUN printf '#!/bin/bash \n\ + set -e \n\ + start_xvfb() { \n\ + Xvfb :99 -screen 0 1024x768x8 -nolisten tcp & \n\ + } \n\ + stop_xvfb() { \n\ + killall Xvfb || true \n\ + } \n\ + trap stop_xvfb SIGTERM \n\ + rm -f /tmp/.X99-lock \n\ + start_xvfb \n\ + echo "[web]" > /work/fhirserver/exec/64/web.ini; \n\ + echo "http=${PORT}" >> /work/fhirserver/exec/64/web.ini; \n\ + /work/fhirserver/exec/64/fhirserver $(eval echo "$@")' > /bin/entrypoint.sh && \ + chmod +x /bin/entrypoint.sh + + +# ENTRYPOINT ["/bin/entrypoint.sh"] + +# CMD ["-cmd", "exec", "-cfg", "/config/config.ini", "-local", "$TERMINOLOGY_CACHE"] + + + +# Runtime stage +FROM ubuntu:22.04 as runtime + +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=UTC +# Set up environment variables +# ENV HOME=~/ +ENV DISPLAY=:99 +ENV PORT=80 +ENV TERMINOLOGY_CACHE=/var/cache/txcache + +# Install runtime dependencies +RUN apt-get update && apt-get install -y wget tzdata xvfb libgtk2.0-0 libsqlite3-dev \ + && rm -rf /var/lib/apt/lists/* \ + && mkdir -p $HOME/fhirserver/config $TERMINOLOGY_CACHE /fhirserver \ + && chmod -R 777 $TERMINOLOGY_CACHE \ + && chmod -R 777 /fhirserver + +# Copy necessary files from the builder stage +COPY --from=builder /work/fhirserver/exec/install.tgz /fhirserver/install.tgz + +# RUN cd /fhirserver \ +# && tar -xzvf install.tgz \ +# && cd ./install \ +# && ./install.sh > install.log 2>&1 + +# Assuming /fhirserver is your working directory +WORKDIR /fhirserver + +# Extract the contents of the tar file +RUN tar -xzvf install.tgz + +# Change working directory to the extracted folder +WORKDIR /fhirserver/install + +# Run the installation script +RUN ./install.sh -nodaemon + # -zero=https://storage.googleapis.com/tx-fhir-org/config.json +### Uncomment and append this line above to the install script, to allow the initial tx config to be loaded + + +# Define entrypoint and command +CMD ["bash", "-c", "cd ~/fhirserver/ && ./start.sh"] + +# Expose the necessary port +EXPOSE 80 \ No newline at end of file diff --git a/FastMM4_AVX512.obj b/FastMM4_AVX512.obj new file mode 100644 index 000000000..25a677b75 Binary files /dev/null and b/FastMM4_AVX512.obj differ diff --git a/build/linux-fhirserver.sh b/build/linux-fhirserver.sh index aa5c863a6..e54ebfe1b 100755 --- a/build/linux-fhirserver.sh +++ b/build/linux-fhirserver.sh @@ -57,3 +57,4 @@ $BUILD/tools/lazarus/lazbuild toolkit2/fhirtoolkit.lpr --build-mode=linux -q -q echo "## compile server" $BUILD/tools/lazarus/lazbuild server/fhirserver.lpr --build-mode=linux -q -q --build-all +find ./exec/64 -type f ! -name "*.*" -exec strip {} \; \ No newline at end of file diff --git a/config/config.ini b/config/config.ini index 4ded9d3ac..a051cb8a6 100644 --- a/config/config.ini +++ b/config/config.ini @@ -1,6 +1,7 @@ [config] -zero=https://storage.googleapis.com/tx-fhir-org +zero=file:/root/fhirserver/default_config version=* +local=/var/cache/txcache user=gg [web] diff --git a/config/config.json b/config/config.json new file mode 100644 index 000000000..302dc0314 --- /dev/null +++ b/config/config.json @@ -0,0 +1,19 @@ +{ + "content" : { + "uv" : { + "packages" : { + "r4" : [ + "hl7.terminology.r4", + "fhir.tx.support.r4" + ] + } + } + }, + "endpoints" : { + "cache" : { + "path" : "/post/tx-cache", + "type" : "folder", + "folder": "/var/cache/txcache" + } + } +} diff --git a/exec/pack/fhirserver.web b/exec/pack/fhirserver.web deleted file mode 100644 index 1e7d4cd0c..000000000 Binary files a/exec/pack/fhirserver.web and /dev/null differ diff --git a/exec/pack/linux/get-openssl.sh b/exec/pack/linux/get-openssl.sh new file mode 100644 index 000000000..43a156fc9 --- /dev/null +++ b/exec/pack/linux/get-openssl.sh @@ -0,0 +1,30 @@ +OPENSSL_DIR=${OPENSSL_DIR:-"/tmp/openssl"} + +apt update && apt install -y libgtk2.0-0 + + +# Check if OpenSSL is not installed +if [ ! -d $OPENSSL_DIR ]; then + echo "OpenSSL not found in $OPENSSL_DIR. Installing..." + apt install -y build-essential + + # Download and build OpenSSL 1.1.1w + pushd /tmp + wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz + tar -xf openssl-1.1.1w.tar.gz + cd openssl-1.1.1w + + ./config --prefix=$OPENSSL_DIR --openssldir=$OPENSSL_DIR + make + make test + make install + popd + + echo "OpenSSL installation completed." +else + echo "OpenSSL is already installed in $OPENSSL_DIR." +fi + + cp $OPENSSL_DIR/lib/*.so* . + + diff --git a/exec/pack/linux/install.sh b/exec/pack/linux/install.sh new file mode 100644 index 000000000..47f6130e1 --- /dev/null +++ b/exec/pack/linux/install.sh @@ -0,0 +1,73 @@ +#!/bin/bash +cd "$(dirname "$0")" + +# Detect architecture +ARCH=$(uname -m) + +INSTALL_PATH=${INSTALL_PATH:-"$HOME/fhirserver"} +CACHE_FOLDER=${CACHE_FOLDER:-"/var/cache/txcache"} +ARM_FILES=./arm_64 +X86_64_FILES=./x86_64 + +set -x + +# Function to run commands with sudo only if not root +run_as_root() { + if [ "$(id -u)" -ne 0 ]; then + sudo "$@" + else + "$@" + fi +} + +run_as_root apt update && run_as_root apt install -y wget tzdata xvfb libgtk2.0-0 libsqlite3-dev curl + +mkdir -p $INSTALL_PATH +mkdir -p $INSTALL_PATH/config +mkdir -p $INSTALL_PATH/default_config +run_as_root mkdir -p $CACHE_FOLDER +run_as_root chmod 1777 $CACHE_FOLDER + +cp bin/* $INSTALL_PATH +cp content/* $INSTALL_PATH +# cp -r config/* $INSTALL_PATH +# cp -r config/config/* $INSTALL_PATH/config +cp -r config/* $INSTALL_PATH/config +cp -r default_config/* $INSTALL_PATH/default_config +cp -r web $INSTALL_PATH + +# Files based on architecture +case $ARCH in + x86_64) + cp $X86_64_FILES/* $INSTALL_PATH + ;; + arm*) + cp $ARM_FILES/* $INSTALL_PATH + ;; + *) + echo "Unsupported architecture: $ARCH" + exit 1 + ;; +esac + +# Create link so that the server can be started from anywhere +ln -s $INSTALL_PATH/start.sh /usr/local/bin/fhirserver + +# Copy the default configuration file +cp "$INSTALL_PATH/default_config/config.json" "$INSTALL_PATH/default_config/config.json" + +# Prepare and install the systemd service file but do not enable or start it +SERVICE_FILE="/etc/systemd/system/fhirserver.service" +echo "[Unit] +Description=FHIR Server + +[Service] +ExecStart=$INSTALL_PATH/fhirserver +# Add other service configurations as needed + +[Install] +WantedBy=multi-user.target" | run_as_root tee $SERVICE_FILE > /dev/null + +echo "Installation to $INSTALL_PATH completed." + +cd $INSTALL_PATH \ No newline at end of file diff --git a/exec/pack/linux/start.sh b/exec/pack/linux/start.sh new file mode 100644 index 000000000..f7e4aedba --- /dev/null +++ b/exec/pack/linux/start.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -e + +# Determine the directory where this script is located (this will be $HOME/fhirserver) +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SERVICE_FILE="/etc/systemd/system/fhirserver.service" + +# Function to start Xvfb +start_xvfb() { + Xvfb :99 -screen 0 1024x768x8 -nolisten tcp & + sleep 2 # Give some time for Xvfb to start +} + +# Function to stop Xvfb +stop_xvfb() { + pkill Xvfb || true +} + +trap stop_xvfb EXIT + +rm -f /tmp/.X99-lock +start_xvfb +export DISPLAY=:99 + +# Parse command-line arguments +DAEMON_MODE="" + +for arg in "$@"; do + case $arg in + -daemon) + DAEMON_MODE="enable" + ;; + -nodaemon) + DAEMON_MODE="disable" + ;; + esac +done + +# Determine which config.ini to use +if [ -f "$SCRIPT_DIR/config/config.ini" ]; then + CONFIG_FILE="$SCRIPT_DIR/config/config.ini" +else + CONFIG_FILE="$SCRIPT_DIR/default_config/config.ini" +fi + +if [ ! -f "$SCRIPT_DIR/config/config.json" ]; then + cp "$SCRIPT_DIR/default_config/config.json" "$SCRIPT_DIR/config/config.json" + echo "File copied successfully." +fi + +# Handle daemon management +if [ "$DAEMON_MODE" == "enable" ]; then + sudo systemctl enable fhirserver.service + sudo systemctl start fhirserver.service +elif [ "$DAEMON_MODE" == "disable" ]; then + sudo systemctl stop fhirserver.service || true + sudo systemctl disable fhirserver.service || true +fi + +# Start the FHIR server using the determined config file +exec "$SCRIPT_DIR/fhirserver" -cmd exec -cfg "$CONFIG_FILE" diff --git a/exec/pack/web.ini b/exec/pack/web.ini new file mode 100644 index 000000000..c40ba4601 --- /dev/null +++ b/exec/pack/web.ini @@ -0,0 +1,2 @@ +[web] +htttp=80 diff --git a/library/fhir3/fhir3_utilities.pas b/library/fhir3/fhir3_utilities.pas index ee6508277..c6afefc48 100644 --- a/library/fhir3/fhir3_utilities.pas +++ b/library/fhir3/fhir3_utilities.pas @@ -6905,7 +6905,4 @@ function TFHIRPractitionerRoleHelper.summary: String; begin result := '??'; end; - end. - - diff --git a/library/fhir4/fhir4_utilities.pas b/library/fhir4/fhir4_utilities.pas index f1d619051..fd9832e95 100644 --- a/library/fhir4/fhir4_utilities.pas +++ b/library/fhir4/fhir4_utilities.pas @@ -7597,4 +7597,3 @@ function TFhirBundleEntryListHelper.append(url: String): TFHIRBundleEntry; end; end. - diff --git a/library/fhir4b/fhir4b_utilities.pas b/library/fhir4b/fhir4b_utilities.pas index d6a512bf8..200a89ac0 100644 --- a/library/fhir4b/fhir4b_utilities.pas +++ b/library/fhir4b/fhir4b_utilities.pas @@ -7491,6 +7491,4 @@ function TFhirBundleEntryListHelper.append(url: String): TFHIRBundleEntry; result := append; result.fullUrl := url; end; - end. - diff --git a/library/fhir5/fhir5_utilities.pas b/library/fhir5/fhir5_utilities.pas index 3d9d1c897..bb7ee41e3 100644 --- a/library/fhir5/fhir5_utilities.pas +++ b/library/fhir5/fhir5_utilities.pas @@ -7082,5 +7082,6 @@ function TFHIRPractitionerRoleHelper.summary: String; result := '??'; end; + end. diff --git a/library/web/fsl_npm_cache.pas b/library/web/fsl_npm_cache.pas index 8ad59c426..92b81fbee 100644 --- a/library/web/fsl_npm_cache.pas +++ b/library/web/fsl_npm_cache.pas @@ -98,7 +98,6 @@ TFHIRPackageManager = class (TFslObject) FCache : TFslMap; FTaskDesc : String; FCaching : boolean; - function PathForPackage(id, ver : String; allowed : TSemanticVersionLevel = semverMinor) : String; function loadArchive(content : TBytes; description : String) : TDictionary; procedure clearCache; @@ -106,7 +105,6 @@ TFHIRPackageManager = class (TFslObject) procedure work(pct : integer; done : boolean; desc : String); procedure progress(sender : TObject; pct : integer); function check(desc : String) : boolean; - function loadPackageFromCache(folder : String) : TNpmPackage; procedure buildPackageIndex(folder : String); function latestPackageVersion(id: String): String; function isIgnored(s : String): boolean; @@ -134,9 +132,11 @@ TFHIRPackageManager = class (TFslObject) procedure ListAllPackages(list : TFslList); overload; function packageExists(id, ver : String; allowed : TSemanticVersionLevel = semverMinor) : boolean; overload; + function PathForPackage(id, ver : String; allowed : TSemanticVersionLevel = semverMinor) : String; function autoInstallPackage(id, ver : String) : boolean; overload; function latestPublishedVersion(id : String) : String; + function loadPackageFromCache(folder : String) : TNpmPackage; function loadPackage(id : String) : TNpmPackage; overload; function loadPackage(id, ver : String) : TNpmPackage; overload; procedure loadPackage(id, ver : String; resources : Array of String; loadInfo : TPackageLoadingInformation); overload; diff --git a/server/endpoint_storage.pas b/server/endpoint_storage.pas index 0ac18de11..6ea060582 100644 --- a/server/endpoint_storage.pas +++ b/server/endpoint_storage.pas @@ -1080,7 +1080,7 @@ function TStorageWebEndpoint.SecureRequest(AContext: TIdContext; ip: String; else if request.Document = PathNoSlash then begin result := 'Home Page'; - ReturnProcessedFile(request, response, Session, '/hompage.html', Common.SourceProvider.AltFile('/homepage.html', PathNoSlash), true) + ReturnProcessedFile(request, response, Session, '/homepage.html', Common.SourceProvider.AltFile('/homepage.html', PathNoSlash), true) end else begin diff --git a/server/endpoint_txsvr.pas b/server/endpoint_txsvr.pas index cd868495e..a652716ad 100644 --- a/server/endpoint_txsvr.pas +++ b/server/endpoint_txsvr.pas @@ -263,12 +263,13 @@ TTerminologyServerWebServer = class (TStorageWebEndpoint) TTerminologyServerEndPoint = class (TStorageEndPoint) private - FStore : TTerminologyFhirServerStorage; +// FStore : TTerminologyFhirServerStorage; UTGFolder : String; FWeb : TTerminologyServerWebServer; FLoadThread : TTerminologyServerDataLoadThread; function version : TFHIRVersion; public + FStore : TTerminologyFhirServerStorage; constructor Create(config : TFHIRServerConfigSection; settings : TFHIRServerSettings; db : TFDBManager; common : TCommonTerminologies; pcm : TFHIRPackageManager; i18n : TI18nSupport); destructor Destroy; override; function summary : String; override; @@ -1414,10 +1415,25 @@ procedure TTerminologyFhirServerStorage.loadPackage(pid: String; ignoreEmptyCode i : integer; list : TFslList; pi : TNpmPackageResource; + fileToLoad: string; begin i := 0; - npm := FServerContext.pcm.loadPackage(pid); + +// FEndPoint. +fileToLoad := filePath([FServerContext.pcm.folder,pid]) ; + + + if (FileExists(fileToLoad)) then + try + npm := FServerContext.pcm.loadPackageFromCache(fileToLoad) + except + on e : Exception do + Logging.log('Error loading package from file '+fileToLoad+': '+e.message); + end + else + npm := FServerContext.pcm.loadPackage(pid); + try Logging.start('Load package '+npm.name+'#'+npm.version); try diff --git a/server/fhirserver.lpi b/server/fhirserver.lpi index df50389d1..c5bb8285d 100644 --- a/server/fhirserver.lpi +++ b/server/fhirserver.lpi @@ -1,3 +1,4 @@ + @@ -20,7 +21,6 @@ - @@ -130,7 +130,7 @@ - + @@ -323,7 +323,7 @@ - + @@ -833,7 +833,7 @@ - + @@ -1036,7 +1036,7 @@ - + diff --git a/server/fhirserver.lpr b/server/fhirserver.lpr index d06adcb2c..f752eda08 100644 --- a/server/fhirserver.lpr +++ b/server/fhirserver.lpr @@ -32,7 +32,7 @@ uses {$IFDEF WINDOWS} - FastMM4, + //FastMM4, {$ELSE} cmem, cthreads, diff --git a/server/kernel.pas b/server/kernel.pas index 30bc5ed38..41c9ef5e7 100644 --- a/server/kernel.pas +++ b/server/kernel.pas @@ -33,7 +33,7 @@ interface Uses - {$IFDEF WINDOWS} Windows, ActiveX, FastMM4, {$ENDIF} + {$IFDEF WINDOWS} Windows, ActiveX, {$ENDIF} SysUtils, StrUtils, Classes, IniFiles, Forms, {$IFDEF FPC} gui_lcl, Interfaces, {$ELSE} gui_vcl, {$ENDIF} @@ -936,7 +936,7 @@ procedure ExecuteFhirServer(params : TCommandLineParameters); else begin {$IFDEF WINDOWS} - noFMMLeakMessageBox := true; + //noFMMLeakMessageBox := true; {$ENDIF} SuppressLeakDialog := true; end; diff --git a/server/web/diagnostics.html b/server/web/diagnostics.html index f952b91c8..34db99e18 100644 --- a/server/web/diagnostics.html +++ b/server/web/diagnostics.html @@ -15,7 +15,7 @@

Current Activity

  • Background Thread: [%status.thread%]
  • CDS client instances: [%status.cds.client%]
  • -
  • [%status.web-total-count%] total requests for [%status.web-total-time%]ms. [%status.web-rest-count%] REST requests for [%status.web-rest-time%]ms. [%status.run-time%] since starting ({%status.run-time.ms%]ms)
  • +
  • [%status.web-total-count%] total requests for [%status.web-total-time%]ms. [%status.web-rest-count%] REST requests for [%status.web-rest-time%]ms. [%status.run-time%] since starting ([%status.run-time.ms%] ms)
[%status.web%]