1 | var pm2 = require('pm2');
|
2 | var async = require('async');
|
3 | var globalModulesDir = require('global-modules');
|
4 | module.exports.run = function () {
|
5 | pm2.connect(function(err) {
|
6 | if (err) {
|
7 | console.log(err);
|
8 | process.exit(2);
|
9 | }
|
10 |
|
11 | pm2.start({
|
12 | name: '0n',
|
13 | script : `${globalModulesDir}/0n/cron.js`,
|
14 | exec_mode : 'fork',
|
15 | max_memory_restart : '100M'
|
16 | }, function(err, apps) {
|
17 | pm2.disconnect();
|
18 | if (err) console.log(err);
|
19 | });
|
20 | });
|
21 | }
|
22 |
|
23 | function sleep(s) {
|
24 | return new Promise(function(resolve, reject) {
|
25 | setTimeout(function () {
|
26 | resolve('Done');
|
27 | }, s * 1000);
|
28 | });
|
29 | }
|
30 |
|
31 | module.exports.stop = function () {
|
32 | var pm2 = require('pm2');
|
33 | pm2.delete('0n', function(err) {})
|
34 | pm2.disconnect();
|
35 | sleep(2)
|
36 | .then((value) => {
|
37 | console.log('Bye bye..');
|
38 | process.exit();
|
39 | })
|
40 | }
|