-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (43 loc) · 1.17 KB
/
app.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
46
47
48
49
50
51
52
53
const express = require('express')
const process = require('process')
process.stdin.resume()
const app = express()
const secs = process.env.SECS || 2
const ms = secs * 1000
app.set('view engine', 'ejs')
app.get('/', (_req, res) => {
console.log(`/ accessed @ ${new Date()}`)
res.render('home')
})
app.get('/sigint', (_req, res) => {
console.log(`/sigint accessed @ ${new Date()}`)
setTimeout(function () {
process.kill(process.pid, 'SIGINT')
}, ms)
res.render('sigint', { secs: secs })
})
app.get('/sigterm', (_req, res) => {
console.log(`/sigterm accessed @ ${new Date()}`)
setTimeout(function () {
process.kill(process.pid, 'SIGTERM')
}, ms)
res.render('sigterm', { secs: secs })
})
app.get('/sigkill', (_req, res) => {
console.log(`/sigkill accessed @ ${new Date()}`)
setTimeout(function () {
process.kill(process.pid, 'SIGKILL')
}, ms)
res.render('sigkill', { secs: secs })
})
function handle(signal) {
console.log(`Received ${signal} @ ${new Date()}`)
if (signal === 'SIGINT') {
process.exit(0)
} else if (signal === 'SIGTERM') {
process.exit(0)
}
}
process.on('SIGINT', handle)
process.on('SIGTERM', handle)
module.exports = app