Skip to content

Commit

Permalink
doc: added doc for mapcache script helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbourianes-kalisio committed Mar 19, 2021
1 parent b52dfb6 commit 450749f
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
18 changes: 16 additions & 2 deletions docs/reference/scripts-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ Usage: `delete_file_if_exist <file>`

Creates the given directory if it does not exist

Usage: `create_directory_if_not_exist <directory`
Usage: `create_directory_if_not_exist <directory>`

### delete_directory_if_exist

Deletes the given directory if it exists.

Usage: `delete_directory_if_exist <directory`
Usage: `delete_directory_if_exist <directory>`

## log

Expand All @@ -62,6 +62,20 @@ Displays error messages.

Usage: `log_error <message>`

## mapcache

### delete_mapcache_tiles

Deletes cached tiles from the given layer. You can control the zoom levels from which it will delete tiles using `from_z` and `to_z` (both included in the deletion). You can also restrict deletion to a given area using a geojson file for example (not required).

Usage: `delete_mapcache_tiles <layer_name> <from_z> <to_z> [area]`

### seed_mapcache_tiles

Seed tiles for the given layer. You can control the zoom levels for which it will seed tiles using `from_z` and `to_z` (both included in the seeding process). You can also restrict seeding to a given area using a geojson file for example (not required).

Usage: `seed_mapcache_tiles <layer_name> <from_z> <to_z> <num_threads> [area]`

## mariadb

### mariadb_db_exists
Expand Down
87 changes: 87 additions & 0 deletions scripts/mapcache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
[[ ! -z "${K_MAPCACHE-}" ]] && return
K_MAPCACHE=1

# Include useful scripts
source ${KARGO_SCRIPTS_PATH}/log.sh
source ${KARGO_SCRIPTS_PATH}/file.sh
source ${KARGO_SCRIPTS_PATH}/swarm.sh

# Define common variables
K_MAPCACHE_CONFIG_PATH="${KARGO_BUILD_PATH}/configs/mapcache"
K_MAPCACHE_DOCKER_RUN="docker run --rm \
--network=${DOCKER_BACK_NETWORK} \
--user=www-data:www-data \
--volume=${MAPCACHE_DATA_PATH}:/mnt/data \
--volume=${K_MAPCACHE_CONFIG_PATH}:/etc/mapcache \
${MAPCACHE_IMAGE}:${MAPCACHE_TAG}"

check_mapcache_area_file() {
# Make sure ${AREA} file is in the mapcache config folder
local FILENAME=${K_MAPCACHE_CONFIG_PATH}/$1
if ! file_exists $FILENAME; then
log_error \"$1\" file must be located in ${K_MAPCACHE_CONFIG_PATH}
return 1
fi

return 0
}

delete_mapcache_tiles() {
local LAYER=$1
local FROM_Z=$2
local TO_Z=$3
local AREA=${4:-}

local MAPCACHE_SEED="mapcache_seed -c /etc/mapcache/mapcache.xml -t ${LAYER} -z ${FROM_Z},${TO_Z} -m delete"
if [ -z "${AREA}" ]; then
log_info deleting ${LAYER} [${FROM_Z} ${TO_Z}] over the planet
echo "${K_MAPCACHE_DOCKER_RUN} ${MAPCACHE_SEED}"
else
if ! check_mapcache_area_file ${AREA}; then
return 1
fi
log_info deleting ${LAYER} [${FROM_Z} ${TO_Z}] over ${AREA}
echo "${K_MAPCACHE_DOCKER_RUN} ${MAPCACHE_SEED} -d ${AREA}"
fi
}

seed_mapcache_tiles() {
local LAYER=$1
local FROM_Z=$2
local TO_Z=$3
local NUM_THREADS=$4
local AREA=${5:-}

local MAPCACHE_SEED="mapcache_seed -c /etc/mapcache/mapcache.xml -t ${LAYER} -z ${FROM_Z},${TO_Z} -n ${NUM_THREADS} -m seed"
if [ -z "${AREA}" ]; then
log_info seeding ${LAYER} [${FROM_Z} ${TO_Z}] over the planet
echo "${K_MAPCACHE_DOCKER_RUN} ${MAPCACHE_SEED}"
else
if ! check_mapcache_area_file ${AREA}; then
return 1
fi
log_info seeding ${LAYER} [${FROM_Z} ${TO_Z}] over ${AREA}
echo "${K_MAPCACHE_DOCKER_RUN} ${MAPCACHE_SEED} -d ${AREA}"
fi
}

# rsync_mapcache_local_cache() {
# local LAYER=${1:-}

# local CACHE_PATH=$MAPCACHE_DATA_PATH
# if [ -n "$LAYER" ] && [ $LAYER != "all" ]; then
# CACHE_PATH=$MAPCACHE_DATA_PATH/$LAYER
# fi

# if ! directory_exists $CACHE_PATH; then
# log_error the cache directory \"${CACHE_PATH}\" doesn\'t exist
# return 1
# fi

# local THIS_NODE=$(this_swarm_node)
# local OTHER_NODES=$(other_swarm_nodes)
# for NODE in ${OTHER_NODES}; do
# echo "k-node-exec -c $NODE \"cd $CACHE_PATH && sudo rm -fR * && sudo rsync -e \"ssh -o StrictHostKeyChecking=accept-new -i $HOME/.ssh/ssh.pem\" -a --no-i-r --info=progress2 $THIS_NODE:$MAPCACHE_DATA_PATH/ . && sudo chown -R www-data:www-data *\""
# done
# }

0 comments on commit 450749f

Please sign in to comment.