1 | 'use strict';
|
2 |
|
3 | var installer = require('./dynamodb/installer'),
|
4 | starter = require('./dynamodb/starter'),
|
5 | utils = require('./dynamodb/utils'),
|
6 | config = require('./dynamodb/config.json'),
|
7 | dbInstances = {};
|
8 |
|
9 | var dynamodb = {
|
10 | install: function(callback, path) {
|
11 | if (path) {
|
12 | config.setup.install_path = path;
|
13 | }
|
14 | installer.install(config, function(msg) {
|
15 | console.log(msg);
|
16 | callback();
|
17 | });
|
18 | },
|
19 | start: function(options) {
|
20 | var instance = starter.start(options, config);
|
21 | dbInstances[instance.port] = {
|
22 | process: instance.proc,
|
23 | options: options
|
24 | };
|
25 | instance.proc.on('close', function(code) {
|
26 | if (code !== null && code !== 0) {
|
27 | console.log('DynamoDB Local failed to start with code', code);
|
28 | }
|
29 | });
|
30 | console.log('Dynamodb Local Started, Visit: http://localhost:' + (options.port || config.start.port) + '/shell');
|
31 | },
|
32 | stop: function(port) {
|
33 | if (dbInstances[port]) {
|
34 | dbInstances[port].process.kill('SIGKILL');
|
35 | delete dbInstances[port];
|
36 | }
|
37 | },
|
38 | restart: function(port) {
|
39 | var options = dbInstances[port].options;
|
40 | this.stop(port);
|
41 | this.start(options);
|
42 | console.log("Successfully restarted dynamodb local on port: " + port);
|
43 | },
|
44 | remove: function(callback) {
|
45 | utils.removeDir(config.setup.install_path, function() {
|
46 | console.log("Successfully removed dynamodb local!");
|
47 | callback();
|
48 | });
|
49 | }
|
50 | };
|
51 | module.exports = dynamodb;
|