Skip to content

Commit

Permalink
docker(install): stop docker daemon gracefully on linux
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Aug 26, 2023
1 parent a6558f6 commit a72977c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/docker/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit a72977c

Please sign in to comment.