xtunnel 1.0.8 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +14 -3
- package/package.json +1 -1
package/index.js
CHANGED
@@ -9,7 +9,11 @@ const config = JSON.parse(fs.readFileSync(path.join(__dirname, './config/default
|
|
9
9
|
|
10
10
|
let rayProcess = null
|
11
11
|
|
12
|
-
process.on('exit',
|
12
|
+
process.on('exit', stop())
|
13
|
+
process.on('SIGINT', stop())
|
14
|
+
process.on('SIGUSR1', stop())
|
15
|
+
process.on('SIGUSR2', stop())
|
16
|
+
process.on('uncaughtException', err => stop() && process.exit(1))
|
13
17
|
|
14
18
|
program.version('1.0.0').description('Tunnel CLI')
|
15
19
|
program.command('* <url>').action(url => url && run(url))
|
@@ -29,25 +33,32 @@ async function run(url) {
|
|
29
33
|
}
|
30
34
|
} catch (error) {
|
31
35
|
console.error(error)
|
36
|
+
console.error('SUBSCRIBE LINK ERROR')
|
32
37
|
}
|
33
38
|
}
|
34
39
|
|
35
40
|
function start() {
|
41
|
+
console.log('TUNNEL START')
|
36
42
|
// 关闭上个进程
|
37
43
|
rayProcess && rayProcess.kill('SIGINT')
|
38
44
|
// 设置系统代理
|
39
45
|
setSystemProxy(config.setting.localHttpPort)
|
40
46
|
// 根据操作系统平台-启动新进程
|
41
|
-
rayProcess = child_process.exec(path.join(__dirname, './core/xray-linux-x64'), (error, stdout, stderr) => error && stop()
|
47
|
+
rayProcess = child_process.exec(path.join(__dirname, './core/xray-linux-x64'), (error, stdout, stderr) => error && stop(true))
|
42
48
|
rayProcess.stdout.on('data', console.log)
|
43
49
|
rayProcess.stderr.on('data', console.error)
|
44
50
|
}
|
45
51
|
|
46
|
-
function stop() {
|
52
|
+
function stop(isRestart) {
|
53
|
+
console.log('TUNNEL STOP')
|
47
54
|
// 关闭上个进程
|
48
55
|
rayProcess && rayProcess.kill('SIGINT')
|
49
56
|
// 取消系统代理
|
50
57
|
setSystemProxy()
|
58
|
+
if (isRestart) {
|
59
|
+
console.error('启动失败(请检查权限/端口占用),重新启动中...')
|
60
|
+
start()
|
61
|
+
}
|
51
62
|
return true
|
52
63
|
}
|
53
64
|
|