2020-09-01 17:31:38 +00:00
|
|
|
import path from 'path'
|
|
|
|
import { readFileSync } from 'fs'
|
2020-09-12 20:31:36 +00:00
|
|
|
import { fileURLToPath } from 'url'
|
2020-09-01 17:31:38 +00:00
|
|
|
import nodewindows from 'node-windows'
|
|
|
|
|
2020-09-08 08:11:42 +00:00
|
|
|
function getPathFromRoot(add) {
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
return path.join(__dirname,'../', add)
|
|
|
|
}
|
|
|
|
|
2020-09-07 00:47:53 +00:00
|
|
|
let config = JSON.parse(readFileSync(getPathFromRoot('./config.json')))
|
2020-09-01 17:31:38 +00:00
|
|
|
|
|
|
|
const Service = nodewindows.Service
|
|
|
|
|
2020-09-07 00:47:53 +00:00
|
|
|
let serviceConfig = {
|
2020-09-01 17:31:38 +00:00
|
|
|
name: config.serviceName,
|
|
|
|
description: config.description,
|
2020-09-07 00:47:53 +00:00
|
|
|
script: getPathFromRoot('./runner.mjs'),
|
2020-09-01 17:31:38 +00:00
|
|
|
env: {
|
|
|
|
name: 'NODE_ENV',
|
|
|
|
value: 'production',
|
|
|
|
},
|
2020-09-07 00:47:53 +00:00
|
|
|
wait: 0,
|
|
|
|
grow: .5,
|
|
|
|
maxRestarts: 10
|
2020-09-01 17:31:38 +00:00
|
|
|
//, workingDirectory: '...'
|
|
|
|
//, allowServiceLogon: true
|
2020-09-07 00:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Service', serviceConfig)
|
|
|
|
|
|
|
|
// Create a new service object
|
|
|
|
let svc = new Service(serviceConfig);
|
2020-09-01 17:31:38 +00:00
|
|
|
|
|
|
|
export default svc
|