-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbootstrap.js
45 lines (39 loc) · 1.03 KB
/
bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const createServer = require('./bin/app.js')
const cluster = require('cluster')
const Utils = require('./bin/utils/index')
const Oimi = require('./bin/index.js')
const config = Utils.readConfig()
const figlet = require('figlet')
const colors = require('colors')
console.log(colors.blue(figlet.textSync('ffandown', 'Small Slant')))
const oimi = new Oimi(
config.downloadDir,
{
thread: config.thread,
verbose: process.env.DEBUG || false,
maxDownloadNum: config.maxDownloadNum,
enableTimeSuffix: config.enableTimeSuffix || false,
},
)
Oimi.prototype.config = config
oimi.ready().then(() => {
createServer({
oimi,
port: config.port,
})
})
process.on('SIGTERM', async () => {
await oimi.killAll()
process.exit(1)
})
process.on('SIGINT', async function () {
if (cluster.isMaster) {
await oimi.killAll()
process.exit(0)
}
})
process.on('exit', async () => {
// 退出之前,杀掉进程
await oimi.killAll()
console.log('\nServer stop')
})