Skip to content

Commit 2b601fd

Browse files
authored
Merge pull request #228 from Tencent/dev
Version 1.2.2
2 parents 66f06ba + 22e6f46 commit 2b601fd

28 files changed

+367
-121
lines changed

bin/proxy/addons.finder.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* !
2+
* Tencent is pleased to support the open source community by making Tencent Server Web available.
3+
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
4+
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
5+
* http://opensource.org/licenses/MIT
6+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
7+
*/
8+
'use strict';
9+
10+
const path = require('path');
11+
let isFirstLoad = false;
12+
let cache = {
13+
config: null
14+
};
15+
16+
17+
if (global[__filename]) {
18+
cache = global[__filename];
19+
} else {
20+
global[__filename] = cache;
21+
isFirstLoad = true;
22+
}
23+
24+
if (isFirstLoad) {
25+
process.dlopen = (function(fn) {
26+
const parent = path.join(__dirname, '..');
27+
28+
return function(module, curr) {
29+
// 检查node私有文件
30+
if (/\.node$/i.test(curr) && curr.indexOf(parent) !== 0) {
31+
// 发现私有node扩展
32+
setTimeout(function() {
33+
require('runtime/md5.checker.js').findNodeCpp(curr);
34+
}, 3000);
35+
}
36+
return fn.apply(this, arguments);
37+
};
38+
})(process.dlopen);
39+
}

bin/proxy/admin.actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module.exports = {
5555

5656
'/reload': function (req, res) {
5757

58-
cp.exec('node --no-warnings ./check.js', {
58+
cp.exec('node --no-warnings ./config.checker.js', {
5959
timeout: 5000,
6060
encoding: 'utf8',
6161
cwd: __dirname

bin/proxy/config.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,24 @@ const path = require('path');
1313
const plug = require('plug');
1414
const Deferred = plug('util/Deferred');
1515
const defaultValue = plug('default/config.default.js');
16-
17-
let isFirstLoad = false;
16+
const processArgs = plug('util/process.args.js');
17+
const cwd = process.cwd();
18+
const currConfig = path.join(cwd, 'tsw.config.js');
1819
let cache = {
1920
config: null
2021
};
2122

22-
2323
if (global[__filename]) {
2424
cache = global[__filename];
2525
} else {
2626
global[__filename] = cache;
27-
isFirstLoad = true;
28-
}
29-
30-
if (isFirstLoad) {
31-
process.dlopen = (function(fn) {
32-
const parent = path.join(__dirname, '..');
33-
34-
return function(module, curr) {
35-
// 检查node私有文件
36-
if (/\.node$/i.test(curr) && curr.indexOf(parent) !== 0) {
37-
// 发现私有node扩展
38-
setTimeout(function() {
39-
require('runtime/md5.check.js').findNodeCpp(curr);
40-
}, 3000);
41-
}
42-
return fn.apply(this, arguments);
43-
};
44-
})(process.dlopen);
4527
}
4628

47-
48-
if (fs.existsSync('/etc/tsw.config.js')) {
29+
if (typeof processArgs.config === 'string') {
30+
cache.config = require(path.resolve(cwd, processArgs.config));
31+
} else if (fs.existsSync(currConfig)) {
32+
cache.config = require(currConfig);
33+
} else if (fs.existsSync('/etc/tsw.config.js')) {
4934
cache.config = require('/etc/tsw.config.js');
5035
} else if (fs.existsSync('/usr/local/node_modules/config.js')) {
5136
cache.config = require('/usr/local/node_modules/config.js');

bin/proxy/http.proxy.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ process.on('uncaughtException', function(e) {
1414

1515

1616
const logger = require('logger');
17+
const lang = require('i18n/lang.js');
1718
const http = require('http');
1819
const https = require('https');
1920
const util = require('util');
@@ -406,15 +407,15 @@ function afterCpu80(cpuUsed) {
406407
timeout: 5000
407408
}, function(err, data, errData) { // eslint-disable-line handle-callback-err
408409
const key = `cpu80.v4:${serverInfo.intranetIp}`;
409-
let content = `<strong>单核CPU${serverInfo.cpu}使用率为${cpuUsed}超过80%, 最近5秒钟CPU Profiler见附件</strong>`;
410+
let content = `<strong>${lang.__('mail.singleCoreCpu')}${serverInfo.cpu}${lang.__('mail.CPUUsageRate')}${cpuUsed}${lang.__('mail.UsageRateGreaterThan80%')}${lang.__('mail.fiveSecondsCpuProfiler')}</strong>`;
410411
let str = '';
411412

412413
if (data) {
413414
str = data;
414415
str = str.replace(/</g, '&gt;');
415416
str = str.replace(/\r\n|\r|\n/g, '<br>');
416417

417-
content += '<p><strong>进程快照:</strong></p><pre style="font-size:12px">' + str + '</pre>';
418+
content += `<p><strong>${lang.__('mail.processSnapshot')}:</strong></p><pre style="font-size:12px">${str}</pre>`;
418419
}
419420

420421

@@ -427,8 +428,8 @@ function afterCpu80(cpuUsed) {
427428
'to': config.mailTo,
428429
'cc': config.mailCC,
429430
'runtimeType': 'CPU',
430-
'msgInfo': `${business.module}[CPU]${serverInfo.intranetIp}单核CPU${serverInfo.cpu}使用率为${cpuUsed}超过80%`,
431-
'title': `${business.module}[CPU]${serverInfo.intranetIp}单核CPU${serverInfo.cpu}使用率为${cpuUsed}超过80%`,
431+
'msgInfo': `${business.module}[CPU]${serverInfo.intranetIp}${lang.__('mail.singleCoreCpu')}${serverInfo.cpu}${lang.__('mail.CPUUsageRate')}${cpuUsed}${lang.__('mail.UsageRateGreaterThan80%')}`,
432+
'title': `${business.module}[CPU]${serverInfo.intranetIp}${lang.__('mail.singleCoreCpu')}${serverInfo.cpu}${lang.__('mail.CPUUsageRate')}${cpuUsed}${lang.__('mail.UsageRateGreaterThan80%')}`,
432433
'content': content,
433434
'attachment': result ? {
434435
fileType: true,

bin/proxy/http.route.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
const logger = require('logger');
12+
const lang = require('i18n/lang.js');
1213
const domain = require('domain');
1314
const serverInfo = require('serverInfo.js');
1415
const config = require('./config.js');
@@ -225,7 +226,7 @@ module.exports = function(req, res) {
225226
}
226227

227228
const key = err.message;
228-
const content = `<p><strong>错误堆栈</strong></p><p><pre><code>${err.stack}</code></pre></p>`;
229+
const content = `<p><strong>${lang.__('mail.errorStack')}</strong></p><p><pre><code>${err.stack}</code></pre></p>`;
229230
mail.SendMail(key, 'js', 600, {
230231
'title': key,
231232
'runtimeType': 'Error',

bin/proxy/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
const plug = require('../tsw/plug.js');
1212

13-
require('./version.js');
13+
require('./version.checker.js');
14+
require('./addons.finder.js');
1415

1516
plug('runtime/Console.hack.js');
1617
plug('runtime/fs.hack.js');

bin/proxy/kill.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33

4-
CUR_DIR=$(cd $(dirname $0); pwd)
4+
CUR_DIR=$(cd $(dirname $0); pwd)
55

66
cd ${CUR_DIR}/../
77
pwd
@@ -12,7 +12,7 @@ echo "strat kill"
1212
echo "ps -fC TSW"
1313
ps -fC TSW
1414

15-
PIDS=$(ps -fC TSW|grep TSW|grep /proxy|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ')
15+
PIDS=$(ps -fC TSW|grep TSW|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ')
1616

1717
if [ "$PIDS" ]
1818
then

bin/proxy/master.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
const logger = require('logger');
12+
const lang = require('i18n/lang.js');
1213
const config = require('./config.js');
1314
const cluster = require('cluster');
1415
const cpuUtil = require('util/cpu.js');
@@ -43,6 +44,11 @@ process.on('warning', function(warning) {
4344
return;
4445
}
4546

47+
if (warning.message && warning.message.indexOf('http2') > -1) {
48+
logger.warn(warning.message);
49+
return;
50+
}
51+
4652
logger.warn(errStr);
4753

4854
setImmediate(function() {
@@ -57,7 +63,7 @@ process.on('warning', function(warning) {
5763
process.on('unhandledRejection', (errorOrReason, currPromise) => {
5864
const errStr = String(errorOrReason && errorOrReason.stack || JSON.stringify(errorOrReason));
5965
const key = String(errorOrReason && errorOrReason.message);
60-
const content = `<p><strong>错误堆栈</strong></p><p><pre><code>${errStr}</code></pre></p>`;
66+
const content = `<p><strong>${lang.__('mail.errorStack')}</strong></p><p><pre><code>${errStr}</code></pre></p>`;
6167

6268
// 恢复上下文
6369
if (currPromise && currPromise.domain) {
@@ -124,18 +130,23 @@ function startServer() {
124130
checkWorkerAlive();
125131
startAdmin();
126132

133+
Object.defineProperty(process, 'title', Object.assign(Object.create(null), {
134+
value: 'TSW',
135+
enumerable: true,
136+
writable: false,
137+
configurable: false
138+
}));
127139
} else {
128140

129-
// 子进程直接引入proxy文件,注意此处else作用域属于子进程作用域,非本程序作用域
130141
process.title = 'TSW/worker/node';
131142
logger.info('start worker....');
132143
require('./http.proxy.js');
133-
require('runtime/JankWatcher.js');
144+
require('runtime/jank.watcher.js');
134145

135146
// 30分钟后开始算
136147
!config.isTest && !config.devMode &&
137148
setTimeout(function() {
138-
require('runtime/md5.check.js').check();
149+
require('runtime/md5.checker.js').check();
139150
}, 30 * 60000);
140151

141152
if (cluster.isMaster && debugOptions.inspectorEnabled) {
@@ -279,12 +290,12 @@ function checkWorkerAlive() {
279290
mail.SendMail(key, 'js', 600, {
280291
'to': config.mailTo,
281292
'cc': config.mailCC,
282-
'runtimeType':'Memory',
283-
'msgInfo': `${serverInfo.intranetIp} 内存超限,服务已重启。请开发人员关注是否存在内存泄露`,
284-
'title': `${serverInfo.intranetIp} 内存超限告警`,
285-
'content': `<p><strong>${serverInfo.intranetIp} 内存超限,服务已重启。请开发人员关注是否存在内存泄露</strong></p>`
293+
'runtimeType': 'Memory',
294+
'msgInfo': `${serverInfo.intranetIp} ${lang.__('mail.memoryExceedingTips')}`,
295+
'title': `${serverInfo.intranetIp} ${lang.__('mail.memoryExceedingWaring')}`,
296+
'content': `<p><strong>${serverInfo.intranetIp} ${lang.__('mail.memoryExceedingTips')}</strong></p>`
286297
});
287-
298+
288299
restartWorker(worker);
289300
}
290301
}

bin/proxy/startup.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ then
2525
echo "exit"
2626
exit 0
2727
else
28-
echo "do nothing, there is no pids"
28+
echo "there is no pids of TSW"
2929
fi
3030

3131
CUR_ARGS=""
@@ -48,6 +48,11 @@ then
4848
./TSW --expose_internals --no-deprecation $CUR_ARGS ./proxy >> ../log/run.log.0 2>&1
4949
else
5050
./TSW --expose_internals --no-deprecation $CUR_ARGS ./proxy >> ../log/run.log.0 2>&1 &
51+
sleep 0.5s
52+
echo "sleep 0.5s"
53+
54+
echo "ps -fC TSW"
55+
ps -fC TSW
5156
echo start down
5257
fi
5358

0 commit comments

Comments
 (0)