Skip to content

Commit 4da08a8

Browse files
committed
fix(OSM): apply dir permission fixes more robustly
1 parent be0c794 commit 4da08a8

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

admin/app/services/docker_service.ts

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export class DockerService {
5656

5757
if (action === 'restart') {
5858
await dockerContainer.restart();
59+
60+
if (service.service_name === DockerService.OPENSTREETMAP_SERVICE_NAME) {
61+
await this._fixOSMPermissions();
62+
}
63+
5964
return {
6065
success: true,
6166
message: `Service ${serviceName} restarted successfully`,
@@ -69,7 +74,17 @@ export class DockerService {
6974
message: `Service ${serviceName} is already running`,
7075
};
7176
}
77+
7278
await dockerContainer.start();
79+
80+
if (service.service_name === DockerService.OPENSTREETMAP_SERVICE_NAME) {
81+
await this._fixOSMPermissions();
82+
}
83+
84+
return {
85+
success: true,
86+
message: `Service ${serviceName} started successfully`,
87+
};
7388
}
7489

7590
return {
@@ -227,6 +242,11 @@ export class DockerService {
227242
this._broadcast(service.service_name, 'starting', `Starting Docker container for service ${service.service_name}...`);
228243
await container.start();
229244

245+
// Ensure OSM directories have correct permissions after install+start
246+
if (service.service_name === DockerService.OPENSTREETMAP_SERVICE_NAME) {
247+
await this._fixOSMPermissions();
248+
}
249+
230250
this._broadcast(service.service_name, 'finalizing', `Finalizing installation of service ${service.service_name}...`);
231251
service.installed = true;
232252
await service.save();
@@ -311,17 +331,8 @@ export class DockerService {
311331
// Ensure osm directory has proper perms for OSM container to write cached files to
312332
this._broadcast(DockerService.OPENSTREETMAP_IMPORT_SERVICE_NAME, 'preinstall', 'Ensuring OSM directory permissions are set correctly...');
313333

314-
// Ensure directories exist
315-
await fs.promises.mkdir(`/osm/db`, { recursive: true });
316-
await fs.promises.mkdir(`/osm/tiles`, { recursive: true });
317-
318-
// Must be able to read directories and read/write files inside
319-
await chmodRecursive(`/osm/db`, 0o755, 0o755);
320-
await chownRecursive(`/osm/db`, 1000, 1000);
321-
322-
// Must be able to read directories and read/write files inside
323-
await chmodRecursive(`/osm/tiles`, 0o755, 0o755);
324-
await chownRecursive(`/osm/tiles`, 1000, 1000);
334+
// Ensure the /osm directories exist and have correct permissions
335+
await this._fixOSMPermissions();
325336

326337
// If the initial import file already exists, delete it so we can ensure it is a good download
327338
const fileExists = await disk.exists(IMPORT_FILE_PATH);
@@ -373,19 +384,32 @@ export class DockerService {
373384
const statusCode = data.StatusCode;
374385
await container.remove();
375386

376-
// Set perms again to ensure they are correct after import process
377-
await chmodRecursive(`/osm/db`, 0o755, 0o755);
378-
await chownRecursive(`/osm/db`, 1000, 1000);
379-
380-
await chmodRecursive(`/osm/tiles`, 0o755, 0o755);
381-
await chownRecursive(`/osm/tiles`, 1000, 1000);
382-
387+
// Run permission fix again in case the import changed perms
388+
await this._fixOSMPermissions();
383389

384390
if (statusCode !== 0) {
385391
throw new Error(`OpenStreetMap data import failed with status code ${statusCode}. Check the log file at ${LOG_PATH} for details.`);
386392
}
387393
}
388394

395+
private async _fixOSMPermissions(): Promise<void> {
396+
try {
397+
// Ensure directories exist
398+
await fs.promises.mkdir(`/osm/db`, { recursive: true });
399+
await fs.promises.mkdir(`/osm/tiles`, { recursive: true });
400+
401+
// Must be able to read directories and read/write files inside
402+
await chmodRecursive(`/osm/db`, 0o755, 0o755);
403+
await chownRecursive(`/osm/db`, 1000, 1000);
404+
405+
// Must be able to read directories and read/write files inside
406+
await chmodRecursive(`/osm/tiles`, 0o755, 0o755);
407+
await chownRecursive(`/osm/tiles`, 1000, 1000);
408+
} catch (error) {
409+
logger.error(`Error fixing OSM permissions: ${error.message}`);
410+
}
411+
}
412+
389413
private _broadcast(service: string, status: string, message: string) {
390414
transmit.broadcast('service-installation', {
391415
service_name: service,

0 commit comments

Comments
 (0)