mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-20 11:38:51 +00:00
03ca0ee9ad
The host config variable HOST_DISCOVERABILITY can be set to true or false, controlling the state of the avahi service. This determines if the device advertises it's presence over mDNS. Change-type: patch Signed-off-by: Cameron Diver <cameron@balena.io> Signed-off-by: Rich Bayliss <rich@balena.io>
33 lines
856 B
TypeScript
33 lines
856 B
TypeScript
import * as config from '../config';
|
|
import * as dbus from './dbus';
|
|
|
|
import log from './supervisor-console';
|
|
|
|
export const initialized = (async () => {
|
|
await config.initialized;
|
|
|
|
config.on('change', (conf) => {
|
|
if (conf.hostDiscoverability != null) {
|
|
switchDiscoverability(conf.hostDiscoverability);
|
|
}
|
|
});
|
|
|
|
await switchDiscoverability(await config.get('hostDiscoverability'));
|
|
})();
|
|
|
|
async function switchDiscoverability(discoverable: boolean) {
|
|
try {
|
|
if (discoverable) {
|
|
log.info('Setting host to discoverable');
|
|
await dbus.startService('avahi-daemon');
|
|
await dbus.startSocket('avahi-daemon');
|
|
} else {
|
|
log.info('Setting host to undiscoverable');
|
|
await dbus.stopService('avahi-daemon');
|
|
await dbus.stopSocket('avahi-daemon');
|
|
}
|
|
} catch (e) {
|
|
log.error('There was an error switching host discoverability:', e);
|
|
}
|
|
}
|