-------------------------------------------
Name:      Qortex Server 2.2 Docker Image 
Company:   Quanergy Systems, Inc.
Copyright: (C) 2021, Quanergy Systems, Inc.
-------------------------------------------

------------------------
SOFTWARE INSTALLATION
------------------------
The below are the instructions to install the docker image and deploy the container.


1. Download the Qortex Server docker image qortex-server_2.2.xxx.tar.gz and settings.xml from from Quanergy Download Center: https://downloads.quanergy.com/. Place the files to a host directory, where the application needs to be executed.

2. Run the below command to load the docker image on the host, where xxx is the current release number.
   $ docker load < qortex-server_2.2.xxx.tar.gz

3. Verify the docker image is deployed on the host.
   $ docker images

   Check "qortex-server" with tag "2.2.xxx" is seen as part of the docker images command.

4. Follow the below commands in case Qortex Server is not installed on the host machine.

   $ sudo adduser --system quanergy --group
   $ sudo mkdir -p /home/quanergy/quanergy/qortex/location
   $ sudo chown -R quanergy:quanergy /home/quanergy

5. Copy the settings.xml file to the location /home/quanergy/quanergy/qortex/location and update the sensor IP in the settings file.
   $ cp settings.xml /home/quanergy/quanergy/qortex/location/

6. Run the below command to activate the Qortex Server license. In case Qortex Server is already installed on the host and the license is activated, skip this step.
   $ docker run --rm --net=host -v /home/quanergy/quanergy/qortex:/home/quanergy/quanergy/qortex -it qortex-server:2.2.xxx --license activate <LICENSE_ID> <PASSWORD>

7. Run the container from the docker image. Make sure complete path is provided for the qortex folder on the host.
   $ docker run --restart=always --net=host -v /home/quanergy/quanergy/qortex:/home/quanergy/quanergy/qortex -dit --name qortex-server qortex-server:2.2.xxx

8. Verify docker container is running.
   $ docker ps -a

9. Verify the object data ouptput. If output is not seen then update settings.xml as mentioned in the note below.
   $ nc 127.0.0.1 17171

Note: 
1. If output is not seen, modify the settings.xml file in the folder /home/quanergy/quanergy/qortex/location. 
<Publisher>
    <Name>QORTEX1_OBJECT_LIST</Name>
    <Format>json</Format>
    <Port>17171</Port>
    <AddDataSize>true</AddDataSize>
    <NetworkByteOrder>false</NetworkByteOrder>
</Publisher>

2. Use "docker logs qortex-server" to see the logs
3. Use "docker rm -f qortex-server" to stop and remove the container
4. Use "docker run --rm --net=host -v /home/quanergy/quanergy/qortex:/home/quanergy/quanergy/qortex -it --name qortex-server qortex-server:2.2.xxx --license deactivate" to deactivate the license.