bin,core: remove workers

This commit is contained in:
Micooz 2018-02-15 18:50:55 +08:00
parent f6a056b88c
commit 45ad20a1b6
3 changed files with 7 additions and 23 deletions

15
bin/bootstrap.js vendored

@ -1,4 +1,3 @@
const cluster = require('cluster');
const fs = require('fs');
/**
@ -21,17 +20,9 @@ module.exports = function bootstrap(configPath, {Hub, Config}) {
try {
const config = obtainConfig(configPath);
Config.test(config);
const workers = config.workers;
if (cluster.isMaster && workers > 0) {
for (let i = 0; i < workers; ++i) {
cluster.fork();
}
console.log(`[bootstrap] started ${workers} workers`);
} else {
const hub = new Hub(config);
hub.run();
process.on('SIGINT', () => hub.terminate(() => process.exit(0)));
}
const hub = new Hub(config);
hub.run();
process.on('SIGINT', () => hub.terminate(() => process.exit(0)));
} catch (err) {
console.error(err);
process.exit(-1);

@ -50,7 +50,6 @@ module.exports = function init({isMinimal, isOverwrite}) {
'dns': [],
'dns_expire': 3600,
'timeout': timeout,
'workers': 0,
'log_path': 'bs-client.log',
'log_level': 'info',
'log_max_days': 30
@ -63,7 +62,6 @@ module.exports = function init({isMinimal, isOverwrite}) {
delete clientJson.dns;
delete clientJson.dns_expire;
delete clientJson.timeout;
delete clientJson.workers;
delete clientJson.log_path;
delete clientJson.log_level;
delete clientJson.log_max_days;
@ -84,7 +82,6 @@ module.exports = function init({isMinimal, isOverwrite}) {
'dns_expire': 3600,
'timeout': timeout,
'redirect': '',
'workers': 0,
'log_path': 'bs-server.log',
'log_level': 'info',
'log_max_days': 30
@ -98,7 +95,6 @@ module.exports = function init({isMinimal, isOverwrite}) {
delete serverJson.dns_expire;
delete serverJson.timeout;
delete serverJson.redirect;
delete serverJson.workers;
delete serverJson.log_path;
delete serverJson.log_level;
delete serverJson.log_max_days;

@ -1,4 +1,3 @@
import cluster from 'cluster';
import dgram from 'dgram';
import net from 'net';
import tls from 'tls';
@ -22,8 +21,6 @@ function makeConnID() {
export class Hub {
_wkId = cluster.worker ? cluster.worker.id : 0;
_tcpServer = null;
_udpServer = null;
@ -57,7 +54,7 @@ export class Hub {
this._tcpRelays.clear();
// server
this._tcpServer.close();
logger.info(`[hub-${this._wkId}] shutdown`);
logger.info(`[hub] shutdown`);
// udp server
this._udpServer.close();
typeof callback === 'function' && callback();
@ -111,7 +108,7 @@ export class Hub {
server.on('proxyConnection', this._onConnection);
server.listen(address, () => {
const service = `${this._config.local_protocol}://${this._config.local_host}:${this._config.local_port}`;
logger.info(`[hub-${this._wkId}] blinksocks client is running at ${service}`);
logger.info(`[hub] blinksocks client is running at ${service}`);
resolve(server);
});
});
@ -125,7 +122,7 @@ export class Hub {
};
const onListening = (server) => {
const service = `${this._config.local_protocol}://${this._config.local_host}:${this._config.local_port}`;
logger.info(`[hub-${this._wkId}] blinksocks server is running at ${service}`);
logger.info(`[hub] blinksocks server is running at ${service}`);
resolve(server);
};
switch (this._config.local_protocol) {
@ -223,7 +220,7 @@ export class Hub {
server.bind({address: this._config.local_host, port: this._config.local_port}, () => {
const service = `udp://${this._config.local_host}:${this._config.local_port}`;
logger.info(`[hub-${this._wkId}] blinksocks udp server is running at ${service}`);
logger.info(`[hub] blinksocks udp server is running at ${service}`);
resolve(server);
});
});