Skip to content

Commit

Permalink
feat(vm): sync clock when resume vm (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackHole1 authored Oct 31, 2023
1 parent efb849d commit 2b00cc9
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/darwin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export class DarwinOVM {
});

const commands = [
"ls",
"mkdir -p {/User/,/var/folders/,/private/}",
"mount -t virtiofs vfkit-share-user /User/",
"mount -t virtiofs vfkit-share-var-folders /var/folders/",
Expand Down Expand Up @@ -306,6 +305,31 @@ export class DarwinOVM {
);
}

public async clocksync(): Promise<void> {
const ssh = new NodeSSH();
await ssh.connect({
host: "127.0.0.1",
username: "root",
password: "1",
port: this.sshPort,
timeout: 20,
});

const commands = [
`date -s @${Math.floor(Date.now() / 1000)}`,
"systemctl restart chrony",
];

await pRetry(async () => {
await ssh.execCommand(commands.join(" && "));
}, {
retries: 3,
interval: 100,
});

ssh.dispose();
}

public async resetPath(): Promise<void> {
await this.overridePath(true);
}
Expand Down Expand Up @@ -386,6 +410,6 @@ export class DarwinOVM {
interval: 500,
});


await this.clocksync();
}
}

0 comments on commit 2b00cc9

Please sign in to comment.