@supacloud/admin 0.7.8 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +27 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -25215,7 +25215,10 @@ class SshTransport {
25215
25215
  let connectionReusable = true;
25216
25216
  let timeoutHandle;
25217
25217
  try {
25218
- const operationPromise = openSftp(conn).then(operation);
25218
+ const operationPromise = openSftp(conn).then(async (sftp) => {
25219
+ await operation(sftp);
25220
+ sftp.end();
25221
+ });
25219
25222
  await Promise.race([
25220
25223
  operationPromise,
25221
25224
  new Promise((_resolve, reject) => {
@@ -26489,7 +26492,7 @@ function requiredRemoteBytes(bundle) {
26489
26492
  const transferBytes = [...bundle.files, ...bundle.verifierArchive ? [bundle.verifierArchive] : []].reduce((total, upload) => total + upload.size, 0);
26490
26493
  return transferBytes * 3 + 512 * 1024 * 1024;
26491
26494
  }
26492
- function prepareDropCommand(paths, bundle) {
26495
+ function buildPrepareDropCommand(paths, bundle) {
26493
26496
  const directories = [
26494
26497
  paths.drop,
26495
26498
  `${paths.drop}/bundle`,
@@ -26502,7 +26505,7 @@ function prepareDropCommand(paths, bundle) {
26502
26505
  return [
26503
26506
  "set -euo pipefail",
26504
26507
  "umask 077",
26505
- `test ! -e ${quoteShell2(paths.drop)} || { echo 'Remote upload drop already exists' >&2; exit 1; }`,
26508
+ `test ! -e ${quoteShell2(paths.drop)} && test ! -L ${quoteShell2(paths.drop)} || { echo 'Remote upload drop already exists' >&2; exit 1; }`,
26506
26509
  "TMP_AVAILABLE_KB=$(df -Pk /tmp | awk 'NR == 2 { print $4 }')",
26507
26510
  "VAR_AVAILABLE_KB=$(df -Pk /var/lib/supacloud | awk 'NR == 2 { print $4 }')",
26508
26511
  `test "${"$"}TMP_AVAILABLE_KB" -ge ${Math.ceil(requiredBytes / 1024)} && test "${"$"}VAR_AVAILABLE_KB" -ge ${Math.ceil(requiredBytes / 1024)} || { echo 'Insufficient remote disk space for verified upgrade staging' >&2; exit 1; }`,
@@ -26511,7 +26514,7 @@ function prepareDropCommand(paths, bundle) {
26511
26514
  `);
26512
26515
  }
26513
26516
  async function prepareRemoteDrop(ssh, paths, bundle) {
26514
- const prepared = await ssh.exec(prepareDropCommand(paths, bundle), 30000);
26517
+ const prepared = await ssh.exec(buildPrepareDropCommand(paths, bundle), 30000);
26515
26518
  if (!prepared.success)
26516
26519
  throw remoteFailure("Unable to prepare remote upload drop", prepared);
26517
26520
  }
@@ -26716,7 +26719,10 @@ function buildAdoptDropScript(paths) {
26716
26719
  "trap 'exit 130' INT",
26717
26720
  "trap 'exit 143' TERM",
26718
26721
  `install -d -o root -g root -m 700 ${quoteShell2(REMOTE_STAGE_ROOT)} ${quoteShell2(REMOTE_RUN_ROOT)} ${quoteShell2(REMOTE_LOG_ROOT)}`,
26719
- 'test ! -e "$STAGE" && test ! -e "$STATUS" && test ! -e "$LOG"',
26722
+ 'if [ -e "$STAGE" ] || [ -L "$STAGE" ] || [ -e "$STATUS" ] || [ -L "$STATUS" ] || [ -e "$LOG" ] || [ -L "$LOG" ]; then',
26723
+ " echo 'Upgrade adoption target already exists' >&2",
26724
+ " exit 1",
26725
+ "fi",
26720
26726
  `systemctl status "$UNIT" >/dev/null 2>&1 && { echo 'Upgrade unit already exists' >&2; exit 1; } || true`,
26721
26727
  "ADOPTION_ACTIVE=true",
26722
26728
  'mv "$DROP" "$STAGE"',
@@ -26793,7 +26799,7 @@ async function startRemoteUpgrade(ssh, paths) {
26793
26799
  }
26794
26800
  throw startFailure;
26795
26801
  }
26796
- function readStateScript(paths) {
26802
+ function buildRemoteStateScript(paths) {
26797
26803
  return [
26798
26804
  "set -euo pipefail",
26799
26805
  `DROP=${quoteShell2(paths.drop)}`,
@@ -26803,11 +26809,11 @@ function readStateScript(paths) {
26803
26809
  `UNIT=${quoteShell2(paths.unit)}`,
26804
26810
  `printf 'STATUS=%s\\n' "$(sed -n '1p' "$STATUS" 2>/dev/null || true)"`,
26805
26811
  `printf 'UNIT=%s\\n' "$(systemctl is-active "$UNIT" 2>/dev/null || true)"`,
26806
- 'if [ -e "$STAGE" ]; then echo STAGE_EXISTS=yes; else echo STAGE_EXISTS=no; fi',
26812
+ 'if [ -e "$STAGE" ] || [ -L "$STAGE" ]; then echo STAGE_EXISTS=yes; else echo STAGE_EXISTS=no; fi',
26807
26813
  'if [ -d "$STAGE" ] && [ ! -L "$STAGE" ]; then echo STAGE_DIRECTORY=yes; else echo STAGE_DIRECTORY=no; fi',
26808
- 'if [ -e "$DROP" ]; then echo DROP_EXISTS=yes; else echo DROP_EXISTS=no; fi',
26809
- 'if [ -e "$STATUS" ]; then echo STATUS_EXISTS=yes; else echo STATUS_EXISTS=no; fi',
26810
- 'if [ -e "$LOG" ]; then echo LOG_EXISTS=yes; else echo LOG_EXISTS=no; fi',
26814
+ 'if [ -e "$DROP" ] || [ -L "$DROP" ]; then echo DROP_EXISTS=yes; else echo DROP_EXISTS=no; fi',
26815
+ 'if [ -e "$STATUS" ] || [ -L "$STATUS" ]; then echo STATUS_EXISTS=yes; else echo STATUS_EXISTS=no; fi',
26816
+ 'if [ -e "$LOG" ] || [ -L "$LOG" ]; then echo LOG_EXISTS=yes; else echo LOG_EXISTS=no; fi',
26811
26817
  'UNIT_LOAD_STATE=$(systemctl show --property=LoadState --value "$UNIT" 2>/dev/null || true)',
26812
26818
  `test -n "$UNIT_LOAD_STATE" || { echo 'Unable to read remote upgrade unit load state' >&2; exit 1; }`,
26813
26819
  `printf 'UNIT_LOAD=%s\\n' "$UNIT_LOAD_STATE"`,
@@ -26829,7 +26835,7 @@ function remoteStatePresence(output, field) {
26829
26835
  return presence === "yes";
26830
26836
  }
26831
26837
  async function readRemoteState(ssh, paths, timeoutMs = REMOTE_STATE_READ_TIMEOUT_MS) {
26832
- const state = await ssh.exec(rootCommand(readStateScript(paths)), timeoutMs);
26838
+ const state = await ssh.exec(rootCommand(buildRemoteStateScript(paths)), timeoutMs);
26833
26839
  if (!state.success)
26834
26840
  throw remoteFailure("Unable to read remote upgrade state", state);
26835
26841
  return {
@@ -26938,6 +26944,14 @@ function assertSuccessfulUnitStoppedNormally(state, paths) {
26938
26944
  return;
26939
26945
  throw remoteReconciliationFailure(`Remote upgrade published SUCCEEDED but the unit stopped abnormally or ambiguously ` + `(state=${state.serviceState} load=${state.unitLoadState})`, [], paths);
26940
26946
  }
26947
+ function failedUnitReachedTerminalState(state) {
26948
+ return unitStoppedNormally(state) || state.serviceState === "failed" && state.unitLoadState === "loaded";
26949
+ }
26950
+ function assertFailedUnitReachedTerminalState(state, paths) {
26951
+ if (failedUnitReachedTerminalState(state))
26952
+ return;
26953
+ throw remoteReconciliationFailure(`Remote upgrade published FAILED but the unit state is ambiguous ` + `(state=${state.serviceState} load=${state.unitLoadState})`, [], paths);
26954
+ }
26941
26955
  function assertTerminalEvidence(state, paths) {
26942
26956
  if (state.status !== "SUCCEEDED" && !state.status.startsWith("FAILED:"))
26943
26957
  return;
@@ -27015,6 +27029,7 @@ async function awaitRemoteUpgrade(ssh, paths) {
27015
27029
  return await completedUpgradeOutput(ssh, paths);
27016
27030
  }
27017
27031
  if (state.status.startsWith("FAILED:") && !unitRunning) {
27032
+ assertFailedUnitReachedTerminalState(state, paths);
27018
27033
  await throwRemoteUpgradeFailure(ssh, paths, state.status);
27019
27034
  }
27020
27035
  if (Date.now() >= observationDeadline) {
@@ -28949,7 +28964,7 @@ Actions: routes, upsert_route, update_route, delete_route, config, get_certifica
28949
28964
  // package.json
28950
28965
  var package_default = {
28951
28966
  name: "@supacloud/admin",
28952
- version: "0.7.8",
28967
+ version: "0.7.9",
28953
28968
  description: "Platform administration CLI for SupaCloud operators",
28954
28969
  type: "module",
28955
28970
  main: "./dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/admin",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "description": "Platform administration CLI for SupaCloud operators",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",