From 4e27b729ed6041c376a31c6bc09cce3c212c3be0 Mon Sep 17 00:00:00 2001 From: valentine-mario Date: Mon, 20 Dec 2021 08:00:26 +0100 Subject: [PATCH] updates implemeted --- bootstrap/create-snapshot.js | 45 ++++++++++++++++++------------------ bootstrap/stop-rnode.js | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/bootstrap/create-snapshot.js b/bootstrap/create-snapshot.js index 6707876b..618878b5 100644 --- a/bootstrap/create-snapshot.js +++ b/bootstrap/create-snapshot.js @@ -2,34 +2,33 @@ const fs = require('fs'); const exec_shell = require('./util/exec_script'); const main = async () => { - //take snapshot name from arg - const arg_input = process.argv[2]; - if (arg_input === undefined) { - console.log('Please specify snapshot name'); - return; - } + try { + //take snapshot name from arg + const arg_input = process.argv[2]; + if (arg_input === undefined) { + console.log('Please specify snapshot name'); + return; + } - //check if .rnode dir exist - const homedir = require('os').homedir(); - if (!fs.existsSync(homedir + '/.rnode')) { - console.log(`Cannot snapshot: ${homedir}/.rnode does not exist`); - return; - } + //check if .rnode dir exist + const homedir = require('os').homedir(); + if (!fs.existsSync(homedir + '/.rnode')) { + console.log(`Cannot snapshot: ${homedir}/.rnode does not exist`); + return; + } - //run stop node script - require('child_process').fork('stop-rnode.js'); + //run stop node script + require('child_process').fork('stop-rnode.js'); - //create snapshot dir - await exec_shell(`mkdir -p snapshot`); - const target = `${__dirname}/snapshot/${arg_input}.tgz`; + //create snapshot dir + fs.mkdirSync('snapshot', { recursive: true }); + const target = `${__dirname}/snapshot/${arg_input}.tgz`; - if (fs.existsSync(target)) { - console.log('snapshot already exist'); - return; + await exec_shell(`cd ~ && tar czf "${target}" .rnode`); + console.log(`snapshot created: ${target}`); + } catch (error) { + console.log(error); } - - await exec_shell(`cd ~ && tar czf "${target}" .rnode`); - console.log(`snapshot created: ${target}`); }; main(); diff --git a/bootstrap/stop-rnode.js b/bootstrap/stop-rnode.js index 3867dec7..63d17412 100644 --- a/bootstrap/stop-rnode.js +++ b/bootstrap/stop-rnode.js @@ -24,7 +24,7 @@ const main = async () => { ) { await exec_shell(`kill ${formatted_string}`); } else { - console.log('Aboring ...'); + console.log('Aborting ...'); } rl.close(); });