From c619b557cd77e26de03fb3e0deb7f47327b19237 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Mon, 19 Feb 2024 05:48:23 +0700 Subject: [PATCH] Add lock for async virtualmin --- package-lock.json | 4 ++-- package.json | 2 +- src/executor/podman.js | 2 -- src/executor/runner.js | 10 +++++++++- src/executor/virtualmin.js | 4 ++++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index deb7328..5408818 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "domcloud-bridge", - "version": "0.43.0", + "version": "0.43.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "domcloud-bridge", - "version": "0.43.0", + "version": "0.43.1", "license": "MIT", "dependencies": { "axios": "^1.6.5", diff --git a/package.json b/package.json index ff28413..610a464 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "domcloud-bridge", - "version": "0.43.0", + "version": "0.43.1", "description": "Deployment runner for DOM Cloud", "main": "app.js", "engines": { diff --git a/src/executor/podman.js b/src/executor/podman.js index 7ea32ae..f1010d1 100644 --- a/src/executor/podman.js +++ b/src/executor/podman.js @@ -1,8 +1,6 @@ import { - cat, executeLock, spawnSudoUtil, - writeTo } from '../util.js'; import { existsSync } from 'fs'; diff --git a/src/executor/runner.js b/src/executor/runner.js index fdeeb2c..e30a454 100644 --- a/src/executor/runner.js +++ b/src/executor/runner.js @@ -2,6 +2,7 @@ import path from "path"; import { detectCanShareSSL, escapeShell, + executeLock, getDbName, getJavaVersion, getLtsPhp, @@ -42,7 +43,7 @@ export default async function runConfig(config, domain, writer, sandbox = false) await writer(s + "\n"); } const virtExec = (program, ...opts) => { - return new Promise((resolve, reject) => { + const corePromise = () => new Promise((resolve, reject) => { var virt = virtualminExec.execFormattedAsync(program, ...opts); virt.stdout.on('data', function (chunk) { writeLog((chunk + '').split('\n').filter(x => x).join('\n').toString()); @@ -55,6 +56,13 @@ export default async function runConfig(config, domain, writer, sandbox = false) (code === 0 ? resolve : reject)(code); }); }); + const optIdx = opts.findIndex(x => !!opts[x].domain) + if (optIdx >= 0) { + const lockPath = 'virtualmin-' + opts[optIdx].domain; + return executeLock(lockPath, corePromise) + } else { + return corePromise(); + } } await writeLog(`DOM Cloud runner v${getVersion()} ref ${getRevision()} in ${domain} at ${new Date().toISOString()}`); if (Array.isArray(config.features) && config.features.length > 0 && config.features[0].create && !sandbox) { diff --git a/src/executor/virtualmin.js b/src/executor/virtualmin.js index 3516818..6dd6cc3 100644 --- a/src/executor/virtualmin.js +++ b/src/executor/virtualmin.js @@ -122,6 +122,10 @@ class VirtualminExecutor { k = "--" + k; if (typeof v === 'boolean') p.push(escapeShell(k)); + else if (Array.isArray(v)) + v.forEach(e => { + p.push(escapeShell(k), escapeShell(e)); + }); else p.push(escapeShell(k), escapeShell(v)); }