forked from 99x/dynamodb-localhost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (49 loc) · 1.59 KB
/
index.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
'use strict';
var installer = require('./dynamodb/installer'),
starter = require('./dynamodb/starter'),
utils = require('./dynamodb/utils'),
config = require('./dynamodb/config.json'),
dbInstances = {};
var dynamodb = {
install: function(callback, path) {
if (path) {
config.setup.install_path = path;
}
installer.install(config, function(msg) {
console.log(msg);
callback();
});
},
start: function(options) {
var instance = starter.start(options, config);
dbInstances[instance.port] = {
process: instance.proc,
options: options
};
instance.proc.on('close', function(code) {
if (code !== null && code !== 0) {
console.log('DynamoDB Local failed to start with code', code);
}
});
console.log('Dynamodb Local Started, Visit: http://localhost:' + (options.port || config.start.port) + '/shell');
},
stop: function(port) {
if (dbInstances[port]) {
dbInstances[port].process.kill('SIGKILL');
delete dbInstances[port];
}
},
restart: function(port) {
var options = dbInstances[port].options;
this.stop(port);
this.start(options);
console.log("Successfully restarted dynamodb local on port: " + port);
},
remove: function(callback) {
utils.removeDir(config.setup.install_path, function() {
console.log("Successfully removed dynamodb local!");
callback();
});
}
};
module.exports = dynamodb;