Skip to content

Commit

Permalink
allow creating relative symlinks to worker sockets; in fact, let's do…
Browse files Browse the repository at this point in the history
… that by default now
  • Loading branch information
jahudka committed Aug 9, 2023
1 parent fdd2745 commit 553ebcf
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/user/03-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The `options` object can contain the following keys:
| `onlineTimeout` | `int` | The timeout for worker processes to report themselves as being online, in milliseconds. The countdown starts when the worker is spawned. This may need to be adjusted if your workers take a long time to initialise. Default: `10000`. |
| `shutdownTimeout` | `int` | The time after sending the worker a `shutdown` message after which more drastic measures should be taken if the worker fails to terminate. Default: `10000`. |
| `maxStartAttempts` | `int` | The maximum number of attempts to start a worker before an error is thrown. This is only applied when an explicit CLI command like `start` or `set-workers` is issued (including starting the daemon itself) - when a worker dies on its own, it will be restarted indefinitely. Default: `1`. |
| `symlinks` | `string` | Specifies how the worker sockets should be referenced in the symlinks exposed to Nginx. Can be either `absolute` or `relative`. By default, the symlinks will be relative. |


## Config files vs. paths
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodesockd",
"version": "2.0.0-rc.6",
"version": "2.0.0-rc.7",
"description": "Bridges a Nginx reverse proxy to a Node.js service using Unix sockets",
"homepage": "https://github.com/cdn77/node-socket-daemon",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const partialOptionsSchema = z.strictObject({
onlineTimeout: z.number().int().min(1).optional(),
shutdownTimeout: z.number().int().min(1).optional(),
maxStartAttempts: z.number().int().min(1).optional(),
symlinks: z.enum(['absolute', 'relative']).optional(),
stdout: z.string().optional(),
stderr: z.string().nullable().optional(),
});
Expand All @@ -31,6 +32,7 @@ const finalOptionsSchema = z.strictObject({
onlineTimeout: z.number().int().min(1).default(10000),
shutdownTimeout: z.number().int().min(1).default(10000),
maxStartAttempts: z.number().int().min(1).default(1),
symlinks: z.enum(['absolute', 'relative']).default('relative'),
stdout: z.string().optional(),
stderr: z.string().nullable().optional(),
});
Expand Down
7 changes: 4 additions & 3 deletions src/daemon/processManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export class ProcessManager extends EventEmitter<ProcessManagerEvents> {

this.logger.debug(`Symlinking socket for worker ${worker.descr}`);
const socketPath = this.formatWorkerSocketPath(worker.idx);
const actualPath = this.formatWorkerSocketPath(worker.id);
const actualPath = this.formatWorkerSocketPath(worker.id, this.config.options.symlinks === 'relative');
const tmpPath = `${socketPath}.new`;
await symlink(actualPath, tmpPath);
await rename(tmpPath, socketPath);
Expand All @@ -428,7 +428,8 @@ export class ProcessManager extends EventEmitter<ProcessManagerEvents> {
} catch { /* noop */ }
}

private formatWorkerSocketPath(worker: number | string): string {
return this.config.socketFile.replace('{worker}', worker.toString());
private formatWorkerSocketPath(worker: number | string, relative: boolean = false): string {
const path = this.config.socketFile.replace('{worker}', worker.toString());
return relative ? path.replace(/^.*\//, './') : path;
}
}

0 comments on commit 553ebcf

Please sign in to comment.