[id: string]: any;
}
let workers: WorkerMap = {};
+let runner: any;
global.serviceType = wrt.getServiceModel();
-function isServiceApplication() {
- return global.serviceType !== 'UI';
+function isStandalone() {
+ return global.serviceType === 'STANDALONE';
+}
+
+function isGlobalService() {
+ return global.serviceType === 'DAEMON';
}
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 && isServiceApplication()) {
+ if (runningServices === 0 && isGlobalService()) {
process.exit();
}
}
export function startService(id: string, filename: string) {
console.log(`startService - ${id}`);
- if (isMainThread) {
- let startService = `${__dirname}/service_runner.js`;
- createWorker(id, startService, filename);
+ if (isStandalone()) {
+ runner = require('../common/service_runner');
+ runner.start(id, filename);
+ } else {
+ if (isMainThread) {
+ let startService = `${__dirname}/service_runner.js`;
+ createWorker(id, startService, filename);
+ }
}
}
export function stopService(id: string) {
console.log(`stopService - ${id}`);
- terminateWorker(id, 500);
+ 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);
+ }
}
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) => {