Add Node config for overwriting socket file if it exists
This commit is contained in:
parent
91448c3005
commit
163c1c2125
@ -1,4 +1,4 @@
|
||||
### Listen config
|
||||
If `type` is `unix`, `path` is the path where to create the socket.
|
||||
If `type` is `unix`, `path` is the path where to create the socket, and `force` is whether to overwrite the socket file if it already exists.
|
||||
|
||||
If `type` is `tcp`, `port` and `host` are the host/port where to listen.
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"listen": {
|
||||
"type": "unix",
|
||||
"path": "/var/run/matrix-appservice-kakaotalk/rpc.sock"
|
||||
"path": "/var/run/matrix-appservice-kakaotalk/rpc.sock",
|
||||
"force": false
|
||||
}
|
||||
}
|
||||
|
@ -46,12 +46,17 @@ export default class ClientManager {
|
||||
}
|
||||
}
|
||||
|
||||
async startUnix(socketPath) {
|
||||
async startUnix(socketPath, force) {
|
||||
try {
|
||||
await fs.promises.access(path.dirname(socketPath))
|
||||
} catch (err) {
|
||||
await fs.promises.mkdir(path.dirname(socketPath), 0o700)
|
||||
}
|
||||
if (force) {
|
||||
try {
|
||||
await fs.promises.unlink(socketPath)
|
||||
} catch (err) {}
|
||||
}
|
||||
await promisify(cb => this.server.listen(socketPath, cb))
|
||||
await fs.promises.chmod(socketPath, 0o700)
|
||||
this.log("Now listening at", socketPath)
|
||||
@ -66,7 +71,7 @@ export default class ClientManager {
|
||||
this.log("Starting server")
|
||||
|
||||
if (this.listenConfig.type === "unix") {
|
||||
await this.startUnix(this.listenConfig.path)
|
||||
await this.startUnix(this.listenConfig.path, this.listenConfig.force)
|
||||
} else if (this.listenConfig.type === "tcp") {
|
||||
await this.startTCP(this.listenConfig.port, this.listenConfig.host)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user