mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-21 02:01:35 +00:00
Allow local mode to be controlled via config.json
Change-type: minor Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
2e80b49da1
commit
a2e2948a4e
@ -52,6 +52,7 @@ class Config extends EventEmitter {
|
||||
supervisorOfflineMode: { source: 'config.json', default: false },
|
||||
hostname: { source: 'config.json', mutable: true },
|
||||
persistentLogging: { source: 'config.json', default: false, mutable: true },
|
||||
localMode: { source: 'config.json', mutable: true, default: 'false' },
|
||||
|
||||
version: { source: 'func' },
|
||||
currentApiKey: { source: 'func' },
|
||||
@ -70,7 +71,6 @@ class Config extends EventEmitter {
|
||||
initialConfigReported: { source: 'db', mutable: true, default: 'false' },
|
||||
initialConfigSaved: { source: 'db', mutable: true, default: 'false' },
|
||||
containersNormalised: { source: 'db', mutable: true, default: 'false' },
|
||||
localMode: { source: 'db', mutable: true, default: 'false' },
|
||||
loggingEnabled: { source: 'db', mutable: true, default: 'true' },
|
||||
connectivityCheckEnabled: { source: 'db', mutable: true, default: 'true' },
|
||||
delta: { source: 'db', mutable: true, default: 'false' },
|
||||
|
57
src/migrations/M00001.js
Normal file
57
src/migrations/M00001.js
Normal file
@ -0,0 +1,57 @@
|
||||
const fs = require('fs');
|
||||
const configJsonPath = process.env.CONFIG_MOUNT_POINT;
|
||||
|
||||
const { checkTruthy } = require('../lib/validation');
|
||||
|
||||
exports.up = function (knex, Promise) {
|
||||
return knex('config').where({ key: 'localMode' }).select('value')
|
||||
.then((results) => {
|
||||
if (results.length === 0) {
|
||||
// We don't need to do anything
|
||||
return;
|
||||
}
|
||||
|
||||
let value = checkTruthy(results[0].value);
|
||||
value = value != null ? value : false;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (!configJsonPath) {
|
||||
console.log('Unable to locate config.json! Things may fail unexpectedly!');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
fs.readFile(configJsonPath, (err, data) => {
|
||||
if (err) {
|
||||
console.log('Failed to read config.json! Things may fail unexpectedly!');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(data.toString());
|
||||
// Assign the local mode value
|
||||
parsed.localMode = value;
|
||||
|
||||
fs.writeFile(configJsonPath, JSON.stringify(parsed), (err) => {
|
||||
if (err) {
|
||||
console.log('Failed to write config.json! Things may fail unexpectedly!');
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.log('Failed to parse config.json! Things may fail unexpectedly!');
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
return knex('config').where('key', 'localMode').del();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function (knex, Promise) {
|
||||
return Promise.reject(new Error('Not Implemented'));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user