myt/myvc-start.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-12-02 07:35:26 +00:00
const MyVC = require('./index');
const docker = require('./docker');
const Server = require('./server/server');
/**
* Does the minium effort to start the database container, if it doesn't
* exists calls the run command, if it is started does nothing. Keep in
* mind that when you do not rebuild the docker you may be using an outdated
* version of it.
*/
class Start {
async run(myvc, opts) {
const server = new Server(opts.code, opts.workspace);
await server.start();
let status;
try {
status = await docker.inspect(opts.code, {
filter: '{{json .State.Status}}'
});
} catch (err) {
return await this.run();
}
switch (status) {
case 'running':
return;
case 'exited':
await docker.start(opts.code);
await this.wait();
return;
default:
throw new Error(`Unknown docker status: ${status}`);
}
}
}
module.exports = Start;
if (require.main === module)
new MyVC().run(Start);