mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-03 23:36:17 +02:00
fix(OSM): apply dir permission fixes more robustly
This commit is contained in:
parent
be0c794d9b
commit
4da08a8312
|
|
@ -56,6 +56,11 @@ export class DockerService {
|
||||||
|
|
||||||
if (action === 'restart') {
|
if (action === 'restart') {
|
||||||
await dockerContainer.restart();
|
await dockerContainer.restart();
|
||||||
|
|
||||||
|
if (service.service_name === DockerService.OPENSTREETMAP_SERVICE_NAME) {
|
||||||
|
await this._fixOSMPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: `Service ${serviceName} restarted successfully`,
|
message: `Service ${serviceName} restarted successfully`,
|
||||||
|
|
@ -69,7 +74,17 @@ export class DockerService {
|
||||||
message: `Service ${serviceName} is already running`,
|
message: `Service ${serviceName} is already running`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await dockerContainer.start();
|
await dockerContainer.start();
|
||||||
|
|
||||||
|
if (service.service_name === DockerService.OPENSTREETMAP_SERVICE_NAME) {
|
||||||
|
await this._fixOSMPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: `Service ${serviceName} started successfully`,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -227,6 +242,11 @@ export class DockerService {
|
||||||
this._broadcast(service.service_name, 'starting', `Starting Docker container for service ${service.service_name}...`);
|
this._broadcast(service.service_name, 'starting', `Starting Docker container for service ${service.service_name}...`);
|
||||||
await container.start();
|
await container.start();
|
||||||
|
|
||||||
|
// Ensure OSM directories have correct permissions after install+start
|
||||||
|
if (service.service_name === DockerService.OPENSTREETMAP_SERVICE_NAME) {
|
||||||
|
await this._fixOSMPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
this._broadcast(service.service_name, 'finalizing', `Finalizing installation of service ${service.service_name}...`);
|
this._broadcast(service.service_name, 'finalizing', `Finalizing installation of service ${service.service_name}...`);
|
||||||
service.installed = true;
|
service.installed = true;
|
||||||
await service.save();
|
await service.save();
|
||||||
|
|
@ -311,17 +331,8 @@ export class DockerService {
|
||||||
// Ensure osm directory has proper perms for OSM container to write cached files to
|
// Ensure osm directory has proper perms for OSM container to write cached files to
|
||||||
this._broadcast(DockerService.OPENSTREETMAP_IMPORT_SERVICE_NAME, 'preinstall', 'Ensuring OSM directory permissions are set correctly...');
|
this._broadcast(DockerService.OPENSTREETMAP_IMPORT_SERVICE_NAME, 'preinstall', 'Ensuring OSM directory permissions are set correctly...');
|
||||||
|
|
||||||
// Ensure directories exist
|
// Ensure the /osm directories exist and have correct permissions
|
||||||
await fs.promises.mkdir(`/osm/db`, { recursive: true });
|
await this._fixOSMPermissions();
|
||||||
await fs.promises.mkdir(`/osm/tiles`, { recursive: true });
|
|
||||||
|
|
||||||
// Must be able to read directories and read/write files inside
|
|
||||||
await chmodRecursive(`/osm/db`, 0o755, 0o755);
|
|
||||||
await chownRecursive(`/osm/db`, 1000, 1000);
|
|
||||||
|
|
||||||
// Must be able to read directories and read/write files inside
|
|
||||||
await chmodRecursive(`/osm/tiles`, 0o755, 0o755);
|
|
||||||
await chownRecursive(`/osm/tiles`, 1000, 1000);
|
|
||||||
|
|
||||||
// If the initial import file already exists, delete it so we can ensure it is a good download
|
// If the initial import file already exists, delete it so we can ensure it is a good download
|
||||||
const fileExists = await disk.exists(IMPORT_FILE_PATH);
|
const fileExists = await disk.exists(IMPORT_FILE_PATH);
|
||||||
|
|
@ -373,19 +384,32 @@ export class DockerService {
|
||||||
const statusCode = data.StatusCode;
|
const statusCode = data.StatusCode;
|
||||||
await container.remove();
|
await container.remove();
|
||||||
|
|
||||||
// Set perms again to ensure they are correct after import process
|
// Run permission fix again in case the import changed perms
|
||||||
await chmodRecursive(`/osm/db`, 0o755, 0o755);
|
await this._fixOSMPermissions();
|
||||||
await chownRecursive(`/osm/db`, 1000, 1000);
|
|
||||||
|
|
||||||
await chmodRecursive(`/osm/tiles`, 0o755, 0o755);
|
|
||||||
await chownRecursive(`/osm/tiles`, 1000, 1000);
|
|
||||||
|
|
||||||
|
|
||||||
if (statusCode !== 0) {
|
if (statusCode !== 0) {
|
||||||
throw new Error(`OpenStreetMap data import failed with status code ${statusCode}. Check the log file at ${LOG_PATH} for details.`);
|
throw new Error(`OpenStreetMap data import failed with status code ${statusCode}. Check the log file at ${LOG_PATH} for details.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _fixOSMPermissions(): Promise<void> {
|
||||||
|
try {
|
||||||
|
// Ensure directories exist
|
||||||
|
await fs.promises.mkdir(`/osm/db`, { recursive: true });
|
||||||
|
await fs.promises.mkdir(`/osm/tiles`, { recursive: true });
|
||||||
|
|
||||||
|
// Must be able to read directories and read/write files inside
|
||||||
|
await chmodRecursive(`/osm/db`, 0o755, 0o755);
|
||||||
|
await chownRecursive(`/osm/db`, 1000, 1000);
|
||||||
|
|
||||||
|
// Must be able to read directories and read/write files inside
|
||||||
|
await chmodRecursive(`/osm/tiles`, 0o755, 0o755);
|
||||||
|
await chownRecursive(`/osm/tiles`, 1000, 1000);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Error fixing OSM permissions: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _broadcast(service: string, status: string, message: string) {
|
private _broadcast(service: string, status: string, message: string) {
|
||||||
transmit.broadcast('service-installation', {
|
transmit.broadcast('service-installation', {
|
||||||
service_name: service,
|
service_name: service,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user