Skip to content

Commit

Permalink
Add lock for async virtualmin
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Feb 18, 2024
1 parent 05bb8f5 commit c619b55
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 0 additions & 2 deletions src/executor/podman.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
cat,
executeLock,
spawnSudoUtil,
writeTo
} from '../util.js';
import { existsSync } from 'fs';

Expand Down
10 changes: 9 additions & 1 deletion src/executor/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path";
import {
detectCanShareSSL,
escapeShell,
executeLock,
getDbName,
getJavaVersion,
getLtsPhp,
Expand Down Expand Up @@ -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());
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/executor/virtualmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit c619b55

Please sign in to comment.