Skip to content

Commit

Permalink
fix: fix mutli deamon run
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Apr 22, 2024
1 parent aa05edb commit a1c1f84
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 30 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.4.1](https://github.com/cnpm/rapid/compare/v0.4.0...v0.4.1) (2024-04-22)


### Bug Fixes

* add rapid_deamon to package ([aa05edb](https://github.com/cnpm/rapid/commit/aa05edbe4f9d532db42e1a3e802bba2468126627))
* fix mutli deamon run ([429b083](https://github.com/cnpm/rapid/commit/429b08393b4fba00f65d47a7e633102fb3751612))





## [0.4.1](https://github.com/cnpm/rapid/compare/v0.4.0...v0.4.1) (2024-04-22)


### Bug Fixes

* add rapid_deamon to package ([aa05edb](https://github.com/cnpm/rapid/commit/aa05edbe4f9d532db42e1a3e802bba2468126627))
* fix mutli deamon run ([429b083](https://github.com/cnpm/rapid/commit/429b08393b4fba00f65d47a7e633102fb3751612))





# [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01)


Expand Down
1 change: 1 addition & 0 deletions bindings/binding-darwin-amd64/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.


# [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01)

**Note:** Version bump only for package @cnpmjs/binding-darwin-x64
Expand Down
2 changes: 1 addition & 1 deletion bindings/binding-darwin-amd64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cnpmjs/binding-darwin-x64",
"version": "0.4.0",
"version": "0.4.1",
"description": "downloader darwin x64 binding",
"main": "index.node",
"homepage": "https://github.com/cnpm/rapid",
Expand Down
1 change: 1 addition & 0 deletions bindings/binding-darwin-arm64/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.


# [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01)

**Note:** Version bump only for package @cnpmjs/binding-darwin-arm64
Expand Down
2 changes: 1 addition & 1 deletion bindings/binding-darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cnpmjs/binding-darwin-arm64",
"version": "0.4.0",
"version": "0.4.1",
"description": "downloader darwin arm64 binding",
"main": "index.node",
"homepage": "https://github.com/cnpm/rapid",
Expand Down
1 change: 1 addition & 0 deletions bindings/binding-linux-amd64/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.


# [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01)

**Note:** Version bump only for package @cnpmjs/binding-linux-x64
Expand Down
2 changes: 1 addition & 1 deletion bindings/binding-linux-amd64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cnpmjs/binding-linux-x64",
"version": "0.4.0",
"version": "0.4.1",
"description": "downloader linux x64 binding",
"main": "index.node",
"homepage": "https://github.com/cnpm/rapid",
Expand Down
1 change: 1 addition & 0 deletions bindings/binding-linux-arm64/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.


# [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01)

**Note:** Version bump only for package @cnpmjs/binding-linux-arm64
Expand Down
2 changes: 1 addition & 1 deletion bindings/binding-linux-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cnpmjs/binding-linux-arm64",
"version": "0.4.0",
"version": "0.4.1",
"description": "downloader linux arm64 binding",
"main": "index.node",
"homepage": "https://github.com/cnpm/rapid",
Expand Down
2 changes: 1 addition & 1 deletion integration/index.2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('test/index.v2.test.js', () => {
await clean({ cwd });
if (process.platform === 'darwin') {
try {
await forceExitDaemon();
await forceExitDaemon(clean);
} catch (err) {
console.warn('force exit daemon error: %s', err.message);
}
Expand Down
2 changes: 1 addition & 1 deletion integration/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('test/index.test.js', () => {
cwd: fixture,
});
if (process.platform === 'darwin') {
await forceExitDaemon();
await forceExitDaemon(clean);
} else {
await exitDaemon();
}
Expand Down
2 changes: 1 addition & 1 deletion integration/workspaces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('test/workspaces.test.js', () => {
force: true,
});
if (process.platform === 'darwin') {
await forceExitDaemon();
await forceExitDaemon(clean);
} else {
await exitDaemon();
}
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.4.0",
"version": "0.4.1",
"lerna": "7.1.4"
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@
},
"engines": {
"node": ">=14.19.1"
},
"rapidVersion": "0.0.1"
}
}
16 changes: 16 additions & 0 deletions packages/binding/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.4.1](https://github.com/cnpm/rapid/compare/v0.4.0...v0.4.1) (2024-04-22)

**Note:** Version bump only for package @cnpmjs/binding





## [0.4.1](https://github.com/cnpm/rapid/compare/v0.4.0...v0.4.1) (2024-04-22)

**Note:** Version bump only for package @cnpmjs/binding





# [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01)


Expand Down
10 changes: 5 additions & 5 deletions packages/binding/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cnpmjs/binding",
"version": "0.4.0",
"version": "0.4.1",
"description": "downloader binding",
"main": "index.js",
"files": [
Expand All @@ -18,10 +18,10 @@
"pack": "npm pack"
},
"optionalDependencies": {
"@cnpmjs/binding-darwin-arm64": "^0.4.0",
"@cnpmjs/binding-darwin-x64": "^0.4.0",
"@cnpmjs/binding-linux-arm64": "^0.4.0",
"@cnpmjs/binding-linux-x64": "^0.4.0"
"@cnpmjs/binding-darwin-arm64": "^0.4.1",
"@cnpmjs/binding-darwin-x64": "^0.4.1",
"@cnpmjs/binding-linux-arm64": "^0.4.1",
"@cnpmjs/binding-linux-x64": "^0.4.1"
},
"devDependencies": {
"@napi-rs/cli": "^2.4.2"
Expand Down
24 changes: 24 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.4.1](https://github.com/cnpm/rapid/compare/v0.4.0...v0.4.1) (2024-04-22)


### Bug Fixes

* add rapid_deamon to package ([aa05edb](https://github.com/cnpm/rapid/commit/aa05edbe4f9d532db42e1a3e802bba2468126627))
* fix mutli deamon run ([429b083](https://github.com/cnpm/rapid/commit/429b08393b4fba00f65d47a7e633102fb3751612))





## [0.4.1](https://github.com/cnpm/rapid/compare/v0.4.0...v0.4.1) (2024-04-22)


### Bug Fixes

* add rapid_deamon to package ([aa05edb](https://github.com/cnpm/rapid/commit/aa05edbe4f9d532db42e1a3e802bba2468126627))
* fix mutli deamon run ([429b083](https://github.com/cnpm/rapid/commit/429b08393b4fba00f65d47a7e633102fb3751612))





# [0.4.0](https://github.com/cnpm/rapid/compare/v0.3.0...v0.4.0) (2024-02-01)


Expand Down
26 changes: 23 additions & 3 deletions packages/cli/lib/deamon.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const runDeamon = async () => {
while (count < 10) {
const res = await checkDeamonAlive();
if (res) {
console.info('[rapid] rapid daemon is running.');
return true;
}
count++;
Expand All @@ -161,6 +162,20 @@ const killDeamon = async () => {
}
};

const clearMetadata = async () => {
try {
await fs.stat(metadataDir);
} catch (error) {
debug('delProject error: ', error);
return false;
}
const files = await fs.readdir(metadataDir);
for (let i = 0; i < files.length; i++) {
const projectName = files[i].split('.')[0];
await delProject(projectName);
}
};

const registerDeamon = async () => {
try {
await execa.command('killall -9 rapid_deamon');
Expand All @@ -176,6 +191,8 @@ const registerDeamon = async () => {

await fs.mkdir(deamonDir, { recursive: true });

await fs.mkdir(nydusdMnt, { recursive: true });

await fs.copyFile(path.join(__dirname, '../package.json'), path.join(deamonDir, 'package.json'));

const nydusConfigPath = path.join(deamonDir, 'nydus_config.json');
Expand Down Expand Up @@ -219,6 +236,8 @@ root:

deamonAutoLauncher.enable();

console.info('[rapid] register rapid daemon end.');

try {
const isEnabled = deamonAutoLauncher.isEnabled();
if (isEnabled) return;
Expand All @@ -230,8 +249,8 @@ root:

const initDeamon = async () => {
try {
const rapidVersion = require(path.join(__dirname, '../package.json')).deamonVersion;
const deamonVersion = require(path.join(deamonDir, './package.json')).deamonVersion;
const rapidVersion = require(path.join(__dirname, '../package.json')).rapidVersion;
const deamonVersion = require(path.join(deamonDir, './package.json')).rapidVersion;

if (compareVersions(deamonVersion, rapidVersion)) {
const err = '[rapid] rapid and deamon version not match';
Expand All @@ -249,9 +268,9 @@ const initDeamon = async () => {
await fs.mkdir(nydusdMnt, { recursive: true });

await fs.stat(destinationFilePath);
await runDeamon();
} catch (e) {
await registerDeamon();
} finally {
await runDeamon();
}
};
Expand All @@ -260,3 +279,4 @@ exports.initDeamon = initDeamon;
exports.delProject = delProject;
exports.addProject = addProject;
exports.killDeamon = killDeamon;
exports.clearMetadata = clearMetadata;
8 changes: 7 additions & 1 deletion packages/cli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const util = require('./util');
const nydusd = require('./nydusd');
const nydusdApi = require('./nydusd/nydusd_api');
const { MirrorConfig } = require('binary-mirror-config');
const { addProject } = require('./deamon');

// 有依赖树(package-lock.json)走 npm / npminstall 极速安装
exports.install = async options => {
Expand Down Expand Up @@ -63,7 +64,7 @@ exports.install = async options => {
await downloadDependency.download(options);

assert(Object.keys(packageLock).length, '[rapid] depsJSON invalid.');
await nydusd.startNydusFs(options.nydusMode, options.cwd, options.pkg, options.daemon);
const deamonConfig = await nydusd.startNydusFs(options.nydusMode, options.cwd, options.pkg, options.daemon);


await util.ensureAccess(options.cwd, packageLock);
Expand All @@ -73,6 +74,11 @@ exports.install = async options => {

console.time('[rapid] run lifecycle scripts');
await options.scripts.runLifecycleScripts(mirrorConfig);

if (options.daemon) {
await addProject(deamonConfig);
}

console.timeEnd('[rapid] run lifecycle scripts');
};

Expand Down
6 changes: 2 additions & 4 deletions packages/cli/lib/nydusd/fuse_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
} = require('../util');
const nydusdApi = require('./nydusd_api');
const { Bar } = require('../logger');
const { addProject, delProject, initDeamon } = require('../deamon');
const { delProject, initDeamon } = require('../deamon');

const getProjectName = cwd => {
const folderName = path.basename(cwd);
Expand Down Expand Up @@ -51,9 +51,7 @@ async function startNydusFs(cwd, pkg, daemon) {
console.log('[rapid] mount overlay, it may take a few seconds');
await mountOverlay(cwd, pkg, deamonConfig);

if (daemon) {
await addProject(deamonConfig);
}
return deamonConfig;
}

async function generateBootstrapFile(cwd, pkg, config) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/nydusd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports.unregisterMode = function(mode) {
exports.startNydusFs = async function(mode, cwd, pkg, daemon) {
const impl = fsImplMap[mode];
assert(impl, `can not find fs impl for mode: ${mode}`);
await impl.start(cwd, pkg, daemon);
return await impl.start(cwd, pkg, daemon);
};

exports.endNydusFs = async function(mode, cwd, pkg, force, daemon) {
Expand Down
14 changes: 11 additions & 3 deletions packages/cli/lib/nydusd/nydusd_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const {
socketPath,
tarBucketsDir,
} = require('../constants');
const { wrapSudo, getWorkdir } = require('../util');
const { killDeamon } = require('../deamon');
const { wrapSudo, getWorkdir, listMountInfo } = require('../util');
const { killDeamon, clearMetadata } = require('../deamon');

// see all APIs at: https://github.com/dragonflyoss/image-service/blob/master/api/openapi/nydus-rs.yaml
const endpoint = 'http://unix/api/v1';
Expand Down Expand Up @@ -140,6 +140,7 @@ async function checkDaemon() {
// 优雅退出 nydusd daemon
async function exitDaemon() {
try {
await clearMetadata();
await killDeamon();
await urllib.request(`${daemonUrl}/exit`, {
method: 'PUT',
Expand All @@ -155,8 +156,15 @@ async function exitDaemon() {

// macos fuse-t 中暂未实现 fuse 的优雅退出只能 umount 之后
// 强制杀掉进程
async function forceExitDaemon() {
async function forceExitDaemon(clean) {
try {
await clearMetadata();
if (clean) {
const currentMountInfo = await listMountInfo();
for (const info of currentMountInfo) {
await clean({ cwd: info.mountPoint });
}
}
await killDeamon();
await execa.command(`umount -f ${nydusdMnt}`);
await execa.command('killall -9 nydusd');
Expand Down
Loading

0 comments on commit a1c1f84

Please sign in to comment.