unix socket support

This commit is contained in:
Travis Glenn Hansen 2019-11-22 13:39:40 -07:00
parent 13e24d3bdd
commit 5af161705f
3 changed files with 64 additions and 7 deletions

View File

@ -54,20 +54,29 @@ const args = require("yargs")
.demandOption(["csi-mode"], "csi-mode is required")
.option("server-address", {
describe: "listen address for the server",
default: "0.0.0.0"
type: "string"
})
.option("server-port", {
describe: "listen port for the server",
default: 50051,
type: "number"
})
.option("server-socket", {
describe: "listen socket for the server",
type: "string"
})
.version()
.help().argv;
if (!args.serverSocket && !args.serverAddress && !args.serverPort) {
console.log("must listen on tcp and/or unix socket");
process.exit(1);
}
const package = require("../package.json");
args.version = package.version;
const grpc = require("grpc");
//const grpc = require("grpc");
const grpc = require("grpc-uds");
const protoLoader = require("@grpc/proto-loader");
const LRU = require("lru-cache");
const cache = new LRU({ max: 500 });
@ -236,15 +245,51 @@ function getServer() {
// https://grpc.github.io/grpc/node/grpc.Server.html
const csiServer = getServer();
let bindAddress = `${args.serverAddress}:${args.serverPort}`;
let bindAddress = "";
let bindSocket = "";
if (args.serverAddress && args.serverPort) {
bindAddress = `${args.serverAddress}:${args.serverPort}`;
}
if (args.serverSocket) {
bindSocket = args.serverSocket || "";
if (!bindSocket.toLowerCase().startsWith("unix://")) {
bindSocket = "unix://" + bindSocket;
}
}
logger.info(
"starting csi server - name: %s, version: %s, driver: %s, mode: %s, csi version: %s, address: %s",
"starting csi server - name: %s, version: %s, driver: %s, mode: %s, csi version: %s, address: %s, socket: %s",
args.csiName,
args.version,
args.driver,
args.csiMode.join(","),
args.csiVersion,
bindAddress
bindAddress,
bindSocket
);
csiServer.bind(bindAddress, grpc.ServerCredentials.createInsecure());
if (bindAddress) {
csiServer.bind(bindAddress, grpc.ServerCredentials.createInsecure());
}
if (bindSocket) {
csiServer.bind(bindSocket, grpc.ServerCredentials.createInsecure());
}
csiServer.start();
[`SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach(
eventType => {
process.on(eventType, code => {
console.log(`running server shutdown, exit code: ${code}`);
let socketPath = args.serverSocket || "";
socketPath = socketPath.replace(/^unix:\/\//g, "");
if (socketPath && fs.existsSync(socketPath)) {
fs.unlinkSync(socketPath);
}
process.exit(code);
});
}
);

11
package-lock.json generated
View File

@ -1206,6 +1206,17 @@
}
}
},
"grpc-uds": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/grpc-uds/-/grpc-uds-0.1.4.tgz",
"integrity": "sha512-AzSJ8SscZuCmqZLyS7i/UbutJDuAkPnfN7wWZzkW7TA+xi7T1g2G7duYc/bgwhB4aTi/RwUs7KemJpKA4W5ZOw==",
"requires": {
"lodash.camelcase": "^4.3.0",
"lodash.clone": "^4.5.0",
"nan": "^2.13.2",
"protobufjs": "^5.0.3"
}
},
"har-schema": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",

View File

@ -22,6 +22,7 @@
"bunyan": "^1.8.12",
"eslint": "^6.6.0",
"grpc": "^1.24.2",
"grpc-uds": "^0.1.4",
"js-yaml": "^3.13.1",
"lru-cache": "^5.1.1",
"request": "^2.88.0",