move server routes into /system
This commit is contained in:
111
src/cloudron.js
111
src/cloudron.js
@@ -4,10 +4,6 @@ exports = module.exports = {
|
||||
initialize,
|
||||
uninitialize,
|
||||
getConfig,
|
||||
getLogs,
|
||||
|
||||
reboot,
|
||||
isRebootRequired,
|
||||
|
||||
onActivated,
|
||||
|
||||
@@ -17,12 +13,6 @@ exports = module.exports = {
|
||||
setDashboardDomain,
|
||||
updateDashboardDomain,
|
||||
|
||||
updateDiskUsage,
|
||||
|
||||
runSystemChecks,
|
||||
|
||||
getBlockDevices,
|
||||
|
||||
getTimeZone,
|
||||
setTimeZone,
|
||||
|
||||
@@ -42,28 +32,20 @@ const apps = require('./apps.js'),
|
||||
dns = require('./dns.js'),
|
||||
dockerProxy = require('./dockerproxy.js'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
fs = require('fs'),
|
||||
logs = require('./logs.js'),
|
||||
mail = require('./mail.js'),
|
||||
moment = require('moment-timezone'),
|
||||
network = require('./network.js'),
|
||||
notifications = require('./notifications.js'),
|
||||
oidc = require('./oidc.js'),
|
||||
path = require('path'),
|
||||
paths = require('./paths.js'),
|
||||
platform = require('./platform.js'),
|
||||
reverseProxy = require('./reverseproxy.js'),
|
||||
safe = require('safetydance'),
|
||||
services = require('./services.js'),
|
||||
settings = require('./settings.js'),
|
||||
shell = require('./shell.js'),
|
||||
tasks = require('./tasks.js'),
|
||||
timers = require('timers/promises'),
|
||||
translation = require('./translation.js'),
|
||||
users = require('./users.js');
|
||||
|
||||
const REBOOT_CMD = path.join(__dirname, 'scripts/reboot.sh');
|
||||
|
||||
async function initialize() {
|
||||
safe(runStartupTasks(), { debug }); // background
|
||||
|
||||
@@ -171,75 +153,6 @@ async function getConfig() {
|
||||
};
|
||||
}
|
||||
|
||||
async function reboot() {
|
||||
await notifications.clearAlert(notifications.ALERT_REBOOT, 'Reboot Required');
|
||||
|
||||
const [error] = await safe(shell.promises.sudo('reboot', [ REBOOT_CMD ], {}));
|
||||
if (error) debug('reboot: could not reboot. %o', error);
|
||||
}
|
||||
|
||||
async function isRebootRequired() {
|
||||
// https://serverfault.com/questions/92932/how-does-ubuntu-keep-track-of-the-system-restart-required-flag-in-motd
|
||||
return fs.existsSync('/var/run/reboot-required');
|
||||
}
|
||||
|
||||
async function runSystemChecks() {
|
||||
debug('runSystemChecks: checking status');
|
||||
|
||||
const checks = [
|
||||
checkMailStatus(),
|
||||
checkRebootRequired(),
|
||||
checkUbuntuVersion()
|
||||
];
|
||||
|
||||
await Promise.allSettled(checks);
|
||||
}
|
||||
|
||||
async function checkMailStatus() {
|
||||
const result = await mail.checkConfiguration();
|
||||
if (result.status) {
|
||||
await notifications.clearAlert(notifications.ALERT_MAIL_STATUS, 'Email is not configured properly');
|
||||
} else {
|
||||
await notifications.alert(notifications.ALERT_MAIL_STATUS, 'Email is not configured properly', result.message, { persist: true });
|
||||
}
|
||||
}
|
||||
|
||||
async function checkRebootRequired() {
|
||||
const rebootRequired = await isRebootRequired();
|
||||
if (rebootRequired) {
|
||||
await notifications.alert(notifications.ALERT_REBOOT, 'Reboot Required', 'To finish ubuntu security updates, a reboot is necessary.', { persist: true });
|
||||
} else {
|
||||
await notifications.clearAlert(notifications.ALERT_REBOOT, 'Reboot Required');
|
||||
}
|
||||
}
|
||||
|
||||
async function checkUbuntuVersion() {
|
||||
const isXenial = fs.readFileSync('/etc/lsb-release', 'utf-8').includes('16.04');
|
||||
if (!isXenial) return;
|
||||
|
||||
await notifications.alert(notifications.ALERT_UPDATE_UBUNTU, 'Ubuntu upgrade required', 'Ubuntu 16.04 has reached end of life and will not receive security and maintenance updates. Please follow https://docs.cloudron.io/guides/upgrade-ubuntu-18/ to upgrade to Ubuntu 18 at the earliest.', { persist: true });
|
||||
}
|
||||
|
||||
async function getLogs(unit, options) {
|
||||
assert.strictEqual(typeof unit, 'string');
|
||||
assert(options && typeof options === 'object');
|
||||
|
||||
debug(`Getting logs for ${unit}`);
|
||||
|
||||
let logFile = '';
|
||||
if (unit === 'box') logFile = path.join(paths.LOG_DIR, 'box.log'); // box.log is at the top
|
||||
else throw new BoxError(BoxError.BAD_FIELD, `No such unit '${unit}'`);
|
||||
|
||||
const cp = logs.tail([logFile], { lines: options.lines, follow: options.follow });
|
||||
|
||||
const logStream = new logs.LogStream({ format: options.format || 'json', source: unit });
|
||||
logStream.close = cp.kill.bind(cp, 'SIGKILL'); // hook for caller. closing stream kills the child process
|
||||
|
||||
cp.stdout.pipe(logStream);
|
||||
|
||||
return logStream;
|
||||
}
|
||||
|
||||
async function prepareDashboardDomain(domain, auditSource) {
|
||||
assert.strictEqual(typeof domain, 'string');
|
||||
assert.strictEqual(typeof auditSource, 'object');
|
||||
@@ -320,30 +233,6 @@ async function setupDnsAndCert(subdomain, domain, auditSource, progressCallback)
|
||||
await reverseProxy.ensureCertificate(location, {}, auditSource);
|
||||
}
|
||||
|
||||
async function updateDiskUsage() {
|
||||
const taskId = await tasks.add(tasks.TASK_UPDATE_DISK_USAGE, []);
|
||||
tasks.startTask(taskId, {});
|
||||
return taskId;
|
||||
}
|
||||
|
||||
async function getBlockDevices() {
|
||||
const info = safe.JSON.parse(safe.child_process.execSync('lsblk --paths --json --list --fs', { encoding: 'utf8' }));
|
||||
if (!info) throw new BoxError(BoxError.INTERNAL_ERROR, safe.error.message);
|
||||
|
||||
const devices = info.blockdevices.filter(d => d.fstype === 'ext4' || d.fstype === 'xfs');
|
||||
|
||||
debug(`getBlockDevices: Found ${devices.length} devices. ${devices.map(d => d.name).join(', ')}`);
|
||||
|
||||
return devices.map(function (d) {
|
||||
return {
|
||||
path: d.name,
|
||||
size: d.fsavail || 0,
|
||||
type: d.fstype,
|
||||
mountpoint: d.mountpoints ? d.mountpoints[0] : d.mountpoint // we only support one mountpoint here old lsblk only exposed one via .mountpoint
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function getTimeZone() {
|
||||
const tz = await settings.get(settings.TIME_ZONE_KEY);
|
||||
return tz || 'UTC';
|
||||
|
||||
Reference in New Issue
Block a user