Browse Source

try catch

master
zeus 3 years ago
parent
commit
b82828aeea
  1. 63
      src-local/llo/new.js

63
src-local/llo/new.js

@ -113,7 +113,14 @@ const { spawn, exec, execSync } = require('child_process')
//const logout = fs.openSync('./logs/out.log', 'a'); //const logout = fs.openSync('./logs/out.log', 'a');
//const logerr = fs.openSync('./logs/out.log', 'a'); //const logerr = fs.openSync('./logs/out.log', 'a');
try {
const logerribuild = fs.openSync('./logs/build-out.log', 'a'); const logerribuild = fs.openSync('./logs/build-out.log', 'a');
} catch (error) {
console.log('Error:', error);
}
//const watcher = chokidar.watch('./logs/build-out.log', { persistent: true }); //const watcher = chokidar.watch('./logs/build-out.log', { persistent: true });
const Tail = require('nodejs-tail'); const Tail = require('nodejs-tail');
@ -1439,8 +1446,20 @@ app.get('/rungui', (req, res, next) => {
var buildoutdir = `${runpath}/logs/build-out.log` var buildoutdir = `${runpath}/logs/build-out.log`
var builderrdir = `${runpath}/logs/build-out.log` var builderrdir = `${runpath}/logs/build-out.log`
//const buildout = fs.openSync(buildoutdir, 'a');
//const builderr = fs.openSync(builderrdir, 'a');
try {
const buildout = fs.openSync(buildoutdir, 'a'); const buildout = fs.openSync(buildoutdir, 'a');
} catch (error) {
console.log('Error:', error);
}
try {
const builderr = fs.openSync(builderrdir, 'a'); const builderr = fs.openSync(builderrdir, 'a');
} catch (error) {
console.log('Error:', error);
}
var buildimage = `echo "EXEC PID: $$"; ${showexec}` var buildimage = `echo "EXEC PID: $$"; ${showexec}`
//var buildimage = `echo "EXEC PID: $$"; docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix microservice-firefox /bin/sh -c "firefox"` //var buildimage = `echo "EXEC PID: $$"; docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix microservice-firefox /bin/sh -c "firefox"`
const run_buildimage = spawn(buildimage, { const run_buildimage = spawn(buildimage, {
@ -2037,7 +2056,11 @@ app.get('/create_config', (req, res, next) => {
RES.value = req.query["value"] RES.value = req.query["value"]
//console.log('value error '+JSON.stringify(RES.value)) //console.log('value error '+JSON.stringify(RES.value))
//var showexec = `cd ./hybrid; /bin/bash ./create-keys.sh` //var showexec = `cd ./hybrid; /bin/bash ./create-keys.sh`
try {
fs.writeFileSync('./hybrid/keys.json', JSON.stringify(RES.value)); fs.writeFileSync('./hybrid/keys.json', JSON.stringify(RES.value));
} catch (error) {
console.log('Error:', error);
}
RES.value = JSON.parse(RES.value); RES.value = JSON.parse(RES.value);
var INTERFACE_IP=RES.value.wg_ip var INTERFACE_IP=RES.value.wg_ip
@ -2080,7 +2103,11 @@ var swarmlab_config_template = `
ip rule add table main suppress_prefixlength 0 ip rule add table main suppress_prefixlength 0
ip rule show | grep -w "suppress_prefixlength" ip rule show | grep -w "suppress_prefixlength"
` `
try {
fs.writeFileSync('./hybrid/connect/swarmlab-connect.sh', swarmlab_config_template); fs.writeFileSync('./hybrid/connect/swarmlab-connect.sh', swarmlab_config_template);
} catch (error) {
console.log('Error:', error);
}
var allowed_ips=RES.value.allowed_ips var allowed_ips=RES.value.allowed_ips
var swarmlab_public_wgkey=RES.value.swarmlab_public_wgkey var swarmlab_public_wgkey=RES.value.swarmlab_public_wgkey
@ -2098,7 +2125,11 @@ var swarmlab_wg0_template = `[Interface]
` `
//fs.writeFileSync('./hybrid/connect/template-wg0.conf', swarmlab_wg0_template); //fs.writeFileSync('./hybrid/connect/template-wg0.conf', swarmlab_wg0_template);
try {
fs.writeFileSync('./hybrid/connect/wg0.conf', swarmlab_wg0_template); fs.writeFileSync('./hybrid/connect/wg0.conf', swarmlab_wg0_template);
} catch (error) {
console.log('Error:', error);
}
var swarmlab_swarm=RES.value.workerkey var swarmlab_swarm=RES.value.workerkey
var swarmlab_swarm_ip=RES.value.swarm_ip var swarmlab_swarm_ip=RES.value.swarm_ip
@ -2106,7 +2137,11 @@ var swarmlab_swarm_template = `
docker swarm join --token ${swarmlab_swarm} ${swarmlab_swarm_ip} docker swarm join --token ${swarmlab_swarm} ${swarmlab_swarm_ip}
` `
//fs.writeFileSync('./hybrid/connect/template-swarm.sh', swarmlab_swarm_template); //fs.writeFileSync('./hybrid/connect/template-swarm.sh', swarmlab_swarm_template);
try {
fs.writeFileSync('./hybrid/connect/reload-swarmlab.sh', swarmlab_swarm_template); fs.writeFileSync('./hybrid/connect/reload-swarmlab.sh', swarmlab_swarm_template);
} catch (error) {
console.log('Error:', error);
}
var swarmlab_swarm_join_template = ` var swarmlab_swarm_join_template = `
@ -2158,7 +2193,11 @@ fi
/bin/bash ${mypath}/hybrid/connect/get-swarmlab-ca /bin/bash ${mypath}/hybrid/connect/get-swarmlab-ca
/bin/bash ${mypath}/hybrid/connect/get-base-ca /bin/bash ${mypath}/hybrid/connect/get-base-ca
` `
try {
fs.writeFileSync('./hybrid/connect/join.sh', swarmlab_swarm_join_template); fs.writeFileSync('./hybrid/connect/join.sh', swarmlab_swarm_join_template);
} catch (error) {
console.log('Error:', error);
}
var swarmlab_swarm_leave_template = ` var swarmlab_swarm_leave_template = `
function hybrid_ifup() { function hybrid_ifup() {
@ -2185,7 +2224,11 @@ else
fi fi
` `
try {
fs.writeFileSync('./hybrid/connect/leave.sh', swarmlab_swarm_leave_template); fs.writeFileSync('./hybrid/connect/leave.sh', swarmlab_swarm_leave_template);
} catch (error) {
console.log('Error:', error);
}
RES.error = false RES.error = false
RES.error_msg = "ok" RES.error_msg = "ok"
@ -2359,7 +2402,11 @@ TEST=${service}
` `
//console.log('value1 '+JSON.stringify(ENV_service_file_path)) //console.log('value1 '+JSON.stringify(ENV_service_file_path))
//console.log('value2 '+JSON.stringify(ENV_service_file)) //console.log('value2 '+JSON.stringify(ENV_service_file))
try {
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'w'}); fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'w'});
} catch (error) {
console.log('Error:', error);
}
var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size
@ -2418,7 +2465,11 @@ TEST=${service}
var ENV_service_file = ` var ENV_service_file = `
SWARMLAB_STORAGE_PASSWORD=${service_password} SWARMLAB_STORAGE_PASSWORD=${service_password}
` `
try {
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'}); fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'});
} catch (error) {
console.log('Error:', error);
}
var service_up = '/bin/bash ./run.sh' var service_up = '/bin/bash ./run.sh'
@ -2472,7 +2523,11 @@ SWARMLAB_STORAGE_PASSWORD=${service_password}
var ENV_service_file = ` var ENV_service_file = `
SWARMLAB_STORAGE_PASSWORD=${service_password} SWARMLAB_STORAGE_PASSWORD=${service_password}
` `
try {
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'}); fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'});
} catch (error) {
console.log('Error:', error);
}
var service_up = '/bin/bash ./run.sh' var service_up = '/bin/bash ./run.sh'
@ -2819,8 +2874,12 @@ SSH_PORT=
//"homefile":"/home/zeus/VirtualBox VMs/ubuntu-/ubuntu-.vbox" //"homefile":"/home/zeus/VirtualBox VMs/ubuntu-/ubuntu-.vbox"
mypath = `${mypath}/builders/bento-swarmlab/${image_dir}` mypath = `${mypath}/builders/bento-swarmlab/${image_dir}`
try {
const buildout = fs.openSync(buildoutdir, 'a'); const buildout = fs.openSync(buildoutdir, 'a');
const builderr = fs.openSync(builderrdir, 'a'); const builderr = fs.openSync(builderrdir, 'a');
} catch (error) {
console.log('Error:', error);
}
var buildimage = `echo "EXEC PID: $$"; packer build -force -only=virtualbox-iso ${image_config}` var buildimage = `echo "EXEC PID: $$"; packer build -force -only=virtualbox-iso ${image_config}`
const run_buildimage = spawn(buildimage, { const run_buildimage = spawn(buildimage, {
@ -3081,7 +3140,11 @@ SSH_PORT=
}; };
let datajson = JSON.stringify(services_json); let datajson = JSON.stringify(services_json);
try {
fs.writeFileSync(rawdatafile, datajson); fs.writeFileSync(rawdatafile, datajson);
} catch (error) {
console.log('Error:', error);
}
var services_path = ` ---------------- var services_path = ` ----------------
create a file create a file

Loading…
Cancel
Save