This repository has been archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
start_value_services.js
167 lines (142 loc) · 4.89 KB
/
start_value_services.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
'use strict';
/**
* Start openST Platform value chain services.
*
* @module tools/setup/start_value_services.js
*/
const rootPrefix = '.';
require(rootPrefix + '/module_overrides/index');
require(rootPrefix + '/lib/providers/platform');
const shellAsyncCmd = require('node-cmd');
// load shelljs and disable output
let shell = require('shelljs');
shell.config.silent = true;
const InstanceComposer = require(rootPrefix + '/instance_composer'),
logger = require(rootPrefix + '/lib/logger/custom_console_logger.js'),
StrategyByGroupHelper = require(rootPrefix + '/helpers/config_strategy/by_group_id'),
homeAbsolutePath = process.env.HOME,
binFolderAbsolutePath = homeAbsolutePath + '/openst-setup/bin';
const args = process.argv,
group_id = args[2];
if (!group_id) {
logger.error('Please pass group_id for fetching strategy. Run the code as: \nnode start_value_services group_id');
process.exit(1);
}
const strategyByGroupHelperObj = new StrategyByGroupHelper(group_id);
/**
* Constructor for start services
*
* @constructor
*/
const StartServicesKlass = function() {};
StartServicesKlass.prototype = {
/**
* Start all platform services
*/
perform: async function() {
const oThis = this,
configStrategyResp = await strategyByGroupHelperObj.getCompleteHash(),
configStrategy = configStrategyResp.data,
ic = new InstanceComposer(configStrategy),
platformProvider = ic.getPlatformProvider(),
openSTPlaform = platformProvider.getInstance(),
valueChainStatus = openSTPlaform.services.utils.valueChainStatus,
servicesList = [];
let cmd = '';
// Start Memcached server
logger.step('** Starting Memcached Server');
cmd = 'memcached -p 11211 -d' + ' >> ' + homeAbsolutePath + '/openst-setup/logs/memcached.log';
// servicesList.push(cmd);
oThis._asyncCommand(cmd);
// Start RabbitMQ server
logger.step('** Starting RabbitMQ Server');
cmd = 'rabbitmq-server' + ' >> ' + homeAbsolutePath + '/openst-setup/logs/rabbitmq.log';
// servicesList.push(cmd);
oThis._asyncCommand(cmd);
// Start Value Chain
logger.step('** Start value chain');
cmd = 'sh ' + binFolderAbsolutePath + '/run-value.sh';
servicesList.push(cmd);
oThis._asyncCommand(cmd);
// Wait for 5 seconds for geth to come up
const sleep = function(ms) {
return new Promise(function(resolve) {
setTimeout(resolve, ms);
});
};
await sleep(5000);
// Check geths are up and running
logger.step('** Check value chain is up and responding');
const statusObj = new valueChainStatus(),
servicesResponse = await statusObj.perform();
if (servicesResponse.isFailure()) {
logger.error('* Error ', servicesResponse);
process.exit(1);
} else {
logger.info('* Value Chain:', servicesResponse.data.chain.value);
}
logger.step('** Starting Processor to execute transactions');
cmd =
'node executables/rmq_subscribers/execute_transaction.js 1' +
' >> ' +
homeAbsolutePath +
'/openst-setup/logs/execute_transaction.log';
servicesList.push(cmd);
oThis._asyncCommand(cmd);
logger.step('** Starting worker to process events');
cmd =
'node executables/rmq_subscribers/factory.js 1' +
' >> ' +
homeAbsolutePath +
'/openst-setup/logs/executables_rmq_subscribers_factory.log';
// servicesList.push(cmd);
oThis._asyncCommand(cmd);
logger.step('** Starting allocate airdrop worker');
cmd =
'node executables/rmq_subscribers/start_airdrop.js 7' +
' >> ' +
homeAbsolutePath +
'/openst-setup/logs/start_airdrop.log';
servicesList.push(cmd);
oThis._asyncCommand(cmd);
logger.step('** Starting SAAS App');
cmd = 'node app.js' + ' >> ' + homeAbsolutePath + '/openst-setup/logs/node_app.log';
servicesList.push(cmd);
oThis._asyncCommand(cmd);
logger.win(
'\n** Congratulations! All services are up and running. \n' +
'NOTE: We will keep monitoring the services, and notify you if any service stops.'
);
// Check all services are running
oThis._uptime(servicesList);
},
/**
* Run async command
*
* @params {string} cmd - command to start the service
* @private
*/
_asyncCommand: function(cmd) {
const oThis = this;
logger.info(cmd);
shellAsyncCmd.run(cmd);
},
/**
* Check if all services are up and running
*
* @params {array} cmds - Array of all running service commands
* @private
*/
_uptime: function(cmds) {
setInterval(function() {
for (let i = 0; i < cmds.length; i++) {
let processID = (shell.exec("ps -ef | grep '" + cmds[i] + "' | grep -v grep | awk '{print $2}'") || {}).stdout;
if (processID === '') {
logger.error('* Process stopped:', cmds[i], ' Please restart the services.');
}
}
}, 5000);
}
};
const services = new StartServicesKlass();
services.perform();