[id: string]: any;
}
let workers: WorkerMap = {};
-let runner: any;
global.serviceType = wrt.getServiceModel();
-function isStandalone() {
- return global.serviceType === 'STANDALONE';
-}
-
-function isGlobalService() {
- return global.serviceType === 'DAEMON';
+function isServiceApplication() {
+ return global.serviceType !== 'UI';
}
function createWorker(id: string, startService: string, filename: string) {
delete workers[id];
let runningServices = Object.keys(workers).length;
console.log('Running services : ' + runningServices);
- if (runningServices === 0 && isGlobalService()) {
+ if (runningServices === 0 && isServiceApplication()) {
process.exit();
}
}
export function startService(id: string, filename: string) {
console.log(`startService - ${id}`);
- if (isStandalone()) {
- runner = require('../common/service_runner');
- runner.start(id, filename);
- } else {
- if (isMainThread) {
- let startService = `${__dirname}/service_runner.js`;
- createWorker(id, startService, filename);
- }
+ if (isMainThread) {
+ let startService = `${__dirname}/service_runner.js`;
+ createWorker(id, startService, filename);
}
}
export function stopService(id: string) {
console.log(`stopService - ${id}`);
- if (isStandalone()) {
- if (!runner) {
- console.log('runner instance is null in standalone mode');
- return;
- }
- runner.stop(id);
- setTimeout(() => process.exit(), 500);
- } else {
- terminateWorker(id, 500);
- }
+ terminateWorker(id, 500);
}
export function handleBuiltinService(serviceId: string, serviceName: string) {
wrt.on('stop-service', (event: any, internal_id: string) => {
ServiceManager.stopService(internal_id);
- if (wrt.getServiceModel() === 'STANDALONE') {
- setTimeout(() => {process.exit()}, 10);
- }
});
wrt.on('builtin-service', (event: any, internal_id: string, service_name: string) => {