Skip to content

Commit 868983d

Browse files
committed
Also allow mounting a /preseed_services.txt to preseed specified services
1 parent 03b4c49 commit 868983d

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

Diff for: README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,20 @@ Add the `qwc-qgs-cache-preseed` container configuration to your QWC `docker-comp
3434
QGS_EXT: ".qgs"
3535
FCGI_INSTANCES: 10
3636
volumes:
37-
- ./volumes/qgs-resources:/data:ro
37+
- ./volumes/preseed_services.txt:/preseed_services.txt:ro
38+
# OR
39+
# - ./volumes/qgs-resources:/data:ro
3840
```
3941

4042
Configuration
4143
-------------
4244

43-
Make sure to mount the `qgs-resources` dir (or whichever directory is mounted to `/data` for `qwc-qgis-server`) to `/data`.
45+
To control which QGS projects will be processed, you can:
46+
47+
- Mount a file to `/preseed_services.txt` which contains the services names, one per line. For example:
48+
- `subdir/projectname` for a QGS file located in `qgs-resources/subdir/projectname.qgs`
49+
- `pg/schema/projectname` for a QGS project located in a DB in schema `schema` and named `projectname`
50+
- Mount the `qgs-resources` dir (or whichever directory is mounted to `/data` for `qwc-qgis-server`) to `/data`, which will be then searches for projects (ending which `$QGS_EXT`).
4451

4552
The following environment variables can be set:
4653

Diff for: qgs_cache_preseed.sh

+17-7
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,32 @@
33
projects=$(find /data -name '*'${QGS_EXT})
44

55
preseed() {
6-
service_name=$1
6+
url=$1
77
nr=$2
88
echo "- Sending request $nr"
9-
code=$(curl -o /dev/null -s -w "%{http_code}" "http://qwc-qgis-server/ows/${service_name}?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0")
9+
code=$(curl -o /dev/null -s -w "%{http_code}" "${url}")
1010
echo "- Request $nr completed with status code $code"
1111
}
1212

13+
if [ -f /preseed_services.txt ]; then
14+
echo "Reading services names from preseed_services.txt..."
15+
service_names=$(cat /preseed_services.txt | sed 's|^/ows/||');
16+
elif [ -d /data ]; then
17+
echo "Scanning /data for projects..."
18+
service_names=$(find /data -name '*'${QGS_EXT} | sed "s|^/data/||; s|${QGS_EXT}$||")
19+
else
20+
echo "No service names found. Mount a file to /preseed_services.txt or mount your projects dir to /data."
21+
exit 0
22+
fi
1323

14-
find /data -name '*'${QGS_EXT} -print0 | while IFS= read -r -d $'\0' file; do
15-
echo "Processing project $file"
16-
service_name=$(echo $file | sed 's|^\/data/||' | sed "s|$QGS_EXT||")
17-
echo "- Service name is ${service_name}"
24+
echo "$service_names" | while IFS= read -r service_name; do
25+
echo "Processing service ${service_name}"
26+
url="http://qwc-qgis-server/ows/${service_name}?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"
27+
echo "- Request URL: ${url}"
1828

1929
pids=""
2030
for i in $(seq 1 $FCGI_INSTANCES); do
21-
preseed "${service_name}" $i &
31+
preseed "${url}" $i &
2232
pid=$!
2333
pids="$pids $pid"
2434
done

0 commit comments

Comments
 (0)