mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-24 15:56:40 +00:00
Use readFromBoot to read VPN status
This removes VPN status monitoring, which would be too expensive to do with a container and is really not necessary. The VPN status information will be available for requests via the supervisor API.
This commit is contained in:
parent
9f8b877819
commit
45d678fd59
@ -1,13 +1,13 @@
|
||||
import * as Bluebird from 'bluebird';
|
||||
import * as _ from 'lodash';
|
||||
import { promises as fs, watch } from 'fs';
|
||||
import { promises as fs } from 'fs';
|
||||
import * as networkCheck from 'network-checker';
|
||||
import * as os from 'os';
|
||||
import * as url from 'url';
|
||||
|
||||
import * as constants from './lib/constants';
|
||||
import { EEXIST } from './lib/errors';
|
||||
import { checkFalsey } from './lib/validation';
|
||||
import { readFromRoot } from './lib/host-utils';
|
||||
|
||||
import blink = require('./lib/blink');
|
||||
|
||||
@ -18,17 +18,12 @@ const networkPattern = {
|
||||
pause: 1000,
|
||||
};
|
||||
|
||||
let isConnectivityCheckPaused = false;
|
||||
let isConnectivityCheckEnabled = true;
|
||||
|
||||
function checkHost(
|
||||
opts: networkCheck.ConnectOptions,
|
||||
): boolean | PromiseLike<boolean> {
|
||||
return (
|
||||
!isConnectivityCheckEnabled ||
|
||||
isConnectivityCheckPaused ||
|
||||
networkCheck.checkHost(opts)
|
||||
);
|
||||
return !isConnectivityCheckEnabled || networkCheck.checkHost(opts);
|
||||
}
|
||||
|
||||
function customMonitor(
|
||||
@ -45,7 +40,7 @@ export function enableCheck(enable: boolean) {
|
||||
export async function isVPNActive(): Promise<boolean> {
|
||||
let active: boolean = true;
|
||||
try {
|
||||
await fs.lstat(`${constants.vpnStatusPath}/active`);
|
||||
await readFromRoot(`${constants.vpnStatusPath}/active`);
|
||||
} catch {
|
||||
active = false;
|
||||
}
|
||||
@ -53,10 +48,6 @@ export async function isVPNActive(): Promise<boolean> {
|
||||
return active;
|
||||
}
|
||||
|
||||
async function vpnStatusInotifyCallback(): Promise<void> {
|
||||
isConnectivityCheckPaused = await isVPNActive();
|
||||
}
|
||||
|
||||
export const startConnectivityCheck = _.once(
|
||||
async (
|
||||
apiEndpoint: string,
|
||||
@ -69,18 +60,6 @@ export const startConnectivityCheck = _.once(
|
||||
return;
|
||||
}
|
||||
|
||||
await Bluebird.resolve(fs.mkdir(constants.vpnStatusPath))
|
||||
.catch(EEXIST, () => {
|
||||
log.debug('VPN status path exists.');
|
||||
})
|
||||
.then(() => {
|
||||
watch(constants.vpnStatusPath, vpnStatusInotifyCallback);
|
||||
});
|
||||
|
||||
if (enable) {
|
||||
vpnStatusInotifyCallback();
|
||||
}
|
||||
|
||||
const parsedUrl = url.parse(apiEndpoint);
|
||||
const port = parseInt(parsedUrl.port!, 10);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user