Merge pull request #2162 from balena-os/host-config-hostname

Do not restart balena-hostname on rename
This commit is contained in:
flowzone-app[bot] 2023-04-20 18:24:17 +00:00 committed by GitHub
commit a9e4bee68e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 23 deletions

View File

@ -185,22 +185,10 @@ async function readHostname() {
}
async function setHostname(val: string) {
// Changing the hostname on config.json will trigger
// the OS config-json service to restart the necessary services
// so the change gets reflected on containers
await config.set({ hostname: val });
// restart balena-hostname if it is loaded and NOT PartOf config-json.target
if (
(
await Promise.any([
dbus.servicePartOf('balena-hostname'),
dbus.servicePartOf('resin-hostname'),
])
).includes('config-json.target') === false
) {
await Promise.any([
dbus.restartService('balena-hostname'),
dbus.restartService('resin-hostname'),
]);
}
}
export async function get(): Promise<HostConfig> {

View File

@ -122,17 +122,10 @@ describe('host-config', () => {
it('patches hostname', async () => {
await hostConfig.patch({ network: { hostname: 'test' } });
// /etc/hostname isn't changed until the balena-hostname service
// is restarted through dbus, so we verify the change from config.
// is restarted by the OS.
expect(await config.get('hostname')).to.equal('test');
});
it('skips restarting hostname services if they are part of config-json.target', async () => {
(dbus.servicePartOf as SinonStub).resolves('config-json.target');
await hostConfig.patch({ network: { hostname: 'newdevice' } });
expect(dbus.restartService as SinonStub).to.not.have.been.called;
expect(await config.get('hostname')).to.equal('newdevice');
});
it('patches proxy', async () => {
await hostConfig.patch({
network: {