Skip to content

Commit

Permalink
update stream chain to stop and start services
Browse files Browse the repository at this point in the history
  • Loading branch information
Cabecinha84 committed Jan 4, 2025
1 parent 8b1608c commit 5a2ac3b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ZelBack/src/services/fluxService.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const path = require('node:path');
const fs = require('node:fs/promises');
const os = require('node:os');
const nodecmd = require('node-cmd');
const { promisify } = require('node:util');

const config = require('config');

// eslint-disable-next-line import/no-extraneous-dependencies
const util = require('util');
const log = require('../lib/log');
const packageJson = require('../../../package.json');
const serviceHelper = require('./serviceHelper');
Expand Down Expand Up @@ -32,6 +34,8 @@ const tar = require('tar/create');
// const stream = require('node:stream/promises');
const stream = require('node:stream');

const isArcane = Boolean(process.env.FLUXOS_PATH);

/**
* Stream chain lock, so only one request at a time
*/
Expand Down Expand Up @@ -1616,7 +1620,7 @@ async function streamChain(req, res) {
res.status(503).end();
return;
}

const cmdAsync = util.promisify(nodecmd.get);
try {
lock = true;

Expand Down Expand Up @@ -1689,6 +1693,11 @@ async function streamChain(req, res) {
res.status(422).end();
return;
}
let execStopServices = 'systemctl stop fluxd.service && systemctl stop flux-watchdog.service';
if (!isArcane) {
execStopServices = 'sudo systemctl stop zelcash.service && pm2 stop watchdog';
}
await cmdAsync(execStopServices);

if (safe) {
const blockInfoRes = await daemonServiceBlockchainRpcs.getBlockchainInfo();
Expand Down Expand Up @@ -1738,7 +1747,14 @@ async function streamChain(req, res) {
const error = await pipeline(...workflow).catch((err) => err);

if (error) log.warn(`Stream error: ${error.code}`);
} catch (error) {
log.error(error);
} finally {
let execStartServices = 'systemctl start fluxd.service && systemctl start flux-watchdog.service';
if (!isArcane) {
execStartServices = 'sudo systemctl start zelcash.service && pm2 start watchdog --watch';
}
cmdAsync(execStartServices);
lock = false;
}
}
Expand Down

0 comments on commit 5a2ac3b

Please sign in to comment.