forked from jembi/openhim-core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenhim-core.js
More file actions
executable file
·39 lines (31 loc) · 967 Bytes
/
Copy pathopenhim-core.js
File metadata and controls
executable file
·39 lines (31 loc) · 967 Bytes
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
#!/usr/bin/env node
const forever = require('forever-monitor')
const path = require('path')
const fs = require('fs')
const args = process.argv
args.splice(0, 2)
/* Check for version flag */
const root = path.join(__dirname, '..')
if (args.indexOf('-v') >= 0 || args.indexOf('--version') >= 0) {
const pkgF = path.join(root, 'package.json')
const pkg = JSON.parse(fs.readFileSync(pkgF))
console.log(`OpenHIM Core version ${pkg.version}`)
process.exit(0)
}
const child = new forever.Monitor('lib/server.js', {
sourceDir: root,
command: 'node',
args,
watch: process.env.NODE_ENV !== 'production',
watchDirectory: 'lib'
})
child.on('watch:restart', info => {
console.error(`Restarting script because ${info.file} changed`)
})
child.on('restart', () => {
console.error(`Forever restarting script for ${child.times} time`)
})
child.on('exit:code', code => {
console.error(`Forever detected script exited with code ${code}`)
})
child.start()