eventlog: add service rebuild/restart/configure events
This commit is contained in:
@@ -40,6 +40,7 @@ const addonConfigs = require('./addonconfigs.js'),
|
||||
crypto = require('crypto'),
|
||||
debug = require('debug')('box:services'),
|
||||
docker = require('./docker.js'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
fs = require('fs'),
|
||||
hat = require('./hat.js'),
|
||||
infra = require('./infra_version.js'),
|
||||
@@ -384,9 +385,10 @@ async function getServiceStatus(id) {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
async function configureService(id, data) {
|
||||
async function configureService(id, data, auditSource) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof data, 'object');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
const [name, instance ] = id.split(':');
|
||||
|
||||
@@ -411,6 +413,8 @@ async function configureService(id, data) {
|
||||
} else {
|
||||
throw new BoxError(BoxError.NOT_FOUND, 'No such service');
|
||||
}
|
||||
|
||||
await eventlog.add(eventlog.ACTION_SERVICE_CONFIGURE, auditSource, { id, data });
|
||||
}
|
||||
|
||||
async function getServiceLogs(id, options) {
|
||||
@@ -490,27 +494,45 @@ async function getServiceLogs(id, options) {
|
||||
return transformStream;
|
||||
}
|
||||
|
||||
async function rebuildService(id) {
|
||||
async function rebuildService(id, auditSource) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
// this attempts to recreate the service docker container if they don't exist but platform infra version is unchanged
|
||||
// passing an infra version of 'none' will not attempt to purge existing data, not sure if this is good or bad
|
||||
// passing an infra version of 'none' will not attempt to purge existing data
|
||||
const serviceConfig = await getServiceConfig(id);
|
||||
|
||||
if (id === 'turn') return await startTurn({ version: 'none' }, serviceConfig);
|
||||
if (id === 'mongodb') return await startMongodb({ version: 'none' });
|
||||
if (id === 'postgresql') return await startPostgresql({ version: 'none' });
|
||||
if (id === 'mysql') return await startMysql({ version: 'none' });
|
||||
if (id === 'sftp') return await sftp.rebuild(serviceConfig, { /* options */ });
|
||||
if (id === 'graphite') return await startGraphite({ version: 'none' }, serviceConfig);
|
||||
switch (id) {
|
||||
case 'turn':
|
||||
await startTurn({ version: 'none' }, serviceConfig);
|
||||
break;
|
||||
case 'mongodb':
|
||||
await startMongodb({ version: 'none' });
|
||||
break;
|
||||
case 'postgresql':
|
||||
await startPostgresql({ version: 'none' });
|
||||
break;
|
||||
case 'mysql':
|
||||
await startMysql({ version: 'none' });
|
||||
break;
|
||||
case 'sftp':
|
||||
await sftp.rebuild(serviceConfig, { /* options */ });
|
||||
break;
|
||||
case 'graphite':
|
||||
await startGraphite({ version: 'none' }, serviceConfig);
|
||||
break;
|
||||
default:
|
||||
// nothing to rebuild for now.
|
||||
}
|
||||
|
||||
// nothing to rebuild for now.
|
||||
// TODO: mongo/postgresql/mysql need to be scaled down.
|
||||
// TODO: missing redis container is not created
|
||||
|
||||
await eventlog.add(eventlog.ACTION_SERVICE_REBUILD, auditSource, { id });
|
||||
}
|
||||
|
||||
async function restartService(id) {
|
||||
async function restartService(id, auditSource) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
|
||||
const [name, instance ] = id.split(':');
|
||||
|
||||
@@ -523,6 +545,8 @@ async function restartService(id) {
|
||||
} else {
|
||||
throw new BoxError(BoxError.NOT_FOUND, 'Service not found');
|
||||
}
|
||||
|
||||
await eventlog.add(eventlog.ACTION_SERVICE_RESTART, auditSource, { id });
|
||||
}
|
||||
|
||||
// in the future, we can refcount and lazy start global services
|
||||
|
||||
Reference in New Issue
Block a user