Skip to content

Commit

Permalink
Fix config to prevent tileserver stalling on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
docuracy committed Dec 24, 2024
1 parent 6c1953a commit 5df3f05
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tileserver/repository/reconfiguration/merge-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,41 @@
// loss of mbtiles' metadata when the server is reconfigured. If the server is already running, it will require a restart
// to apply the changes.

// To prevent startup stalling, it also removes from the configuration file any references to mbtiles that are not
// present in the server's data directory.

const fs = require('fs');

const baseConfigPath = process.argv[2];
const configPath = process.argv[3];

const fileExists = (path) => {
try {
return fs.existsSync(path);
} catch (e) {
return false;
}
};

try {
const baseConfig = JSON.parse(fs.readFileSync(baseConfigPath, 'utf8'));
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));

// Remove data entries for missing mbtiles files
if (config.data && Array.isArray(config.data)) {
config.data = config.data.filter(tile => {
if (tile.file && !fileExists(tile.file)) {
console.log(`Removing missing tile file: ${tile.file}`);
return false; // Exclude this tile entry
}
return true;
});
}

// Merge the data from config into the base config
baseConfig.data = config.data;

// Write the updated configuration back to the config file
fs.writeFileSync(configPath, JSON.stringify(baseConfig, null, 2));
console.log('Config merged successfully');
} catch (error) {
Expand Down

0 comments on commit 5df3f05

Please sign in to comment.