From a72977ca69c74c05ed1bd855a44602e9efd7bbb3 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 26 Aug 2023 12:15:25 +0200 Subject: [PATCH] docker(install): stop docker daemon gracefully on linux Signed-off-by: CrazyMax --- src/docker/install.ts | 8 ++++++-- src/util.ts | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/docker/install.ts b/src/docker/install.ts index 8c19e7e1..bd6c8197 100644 --- a/src/docker/install.ts +++ b/src/docker/install.ts @@ -311,13 +311,17 @@ export class Install { core.info(fs.readFileSync(path.join(this.runDir, 'dockerd.log'), {encoding: 'utf8'})); }); await core.group('Stopping Docker daemon', async () => { - await Exec.exec('sudo', ['kill', fs.readFileSync(path.join(this.runDir, 'docker.pid')).toString().trim()]); + await Exec.exec('sudo', ['kill', '-s', 'SIGTERM', fs.readFileSync(path.join(this.runDir, 'docker.pid')).toString().trim()]); + await Util.sleep(5); }); await core.group('Removing Docker context', async () => { await Exec.exec('docker', ['context', 'rm', '-f', this.contextName]); }); await core.group(`Cleaning up runDir`, async () => { - await Exec.exec('sudo', ['rm', '-rf', this.runDir]); + await Exec.exec('sudo', ['rm', '-rf', this.runDir], { + ignoreReturnCode: true, + failOnStdErr: false + }); }); } diff --git a/src/util.ts b/src/util.ts index 84373b36..faeed7e0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -133,4 +133,8 @@ export class Util { } return str.substring(0, index); } + + public static sleep(seconds: number) { + return new Promise(resolve => setTimeout(resolve, seconds * 1000)); + } }