From 0a350b28857f7ecd6cfc6a6c91c617a1c4792c6d Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 15:36:47 -0500 Subject: [PATCH 01/30] tried a fix --- lxc.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lxc.js b/lxc.js index 73098a5..3135f82 100644 --- a/lxc.js +++ b/lxc.js @@ -21,7 +21,7 @@ module.exports = function(config){ var runCommand = sshBind.slice(); runCommand.push(command); } else { - var runCommand = textToArgs(command); + var runCommand = textToArgs('unset XDG_SESSION_ID XDG_RUNTIME_DIR; cgm movepid all virt $$; '+command); } var errors = ''; @@ -120,6 +120,5 @@ module.exports = function(config){ }); }; - return obj; }; \ No newline at end of file From d1f35c0b7bdc5984469239a349971ee8f3c14bf5 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 15:37:04 -0500 Subject: [PATCH 02/30] tried a fix --- routes/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/index.js b/routes/index.js index 1c75508..8dfa020 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,7 +3,7 @@ var router = express.Router(); var extend = require('node.extend'); var redis = require("redis"); var client = redis.createClient(); -var lxc = require('../lxc')({sshBind: ['/usr/bin/ssh', 'virt@127.0.0.1']}); +var lxc = require('../lxc')(/*{sshBind: ['/usr/bin/ssh', 'virt@127.0.0.1']}*/); //lxc.startEphemeral('ubuntu_template', 'ue0', function(){console.log('cb1', arguments)}, function(){console.log('cb2', arguments)}) router.get('/start/:name', function(req, res, next){ From 8c26dbf8485f7a47102e10fe4f8139b24a9083a0 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 15:55:42 -0500 Subject: [PATCH 03/30] updated package fill --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index dde6f7f..598161a 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ "ejs": "~2.3.3", "express": "~4.13.1", "morgan": "~1.6.1", - "serve-favicon": "~2.3.0" + "serve-favicon": "~2.3.0", + "node.extend": "~1.1.5", + "redis": "~2.4.2" } -} \ No newline at end of file +} From 413d51b0461f963325a5cfdd7748573c503cdbb5 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 15:59:17 -0500 Subject: [PATCH 04/30] added packages --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 598161a..79b3cf1 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,9 @@ "morgan": "~1.6.1", "serve-favicon": "~2.3.0", "node.extend": "~1.1.5", - "redis": "~2.4.2" + "redis": "~2.4.2", + "child": "0.0.3", + "colors": "~1.1.2", + "async": "~1.5.2" } } From 6b1d79f0aaed7e3d305ba0cdb261a21170143074 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:00:15 -0500 Subject: [PATCH 05/30] config issue --- routes/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/index.js b/routes/index.js index 8dfa020..45f0b1d 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,7 +3,7 @@ var router = express.Router(); var extend = require('node.extend'); var redis = require("redis"); var client = redis.createClient(); -var lxc = require('../lxc')(/*{sshBind: ['/usr/bin/ssh', 'virt@127.0.0.1']}*/); +var lxc = require('../lxc')({sshBind: false/*['/usr/bin/ssh', 'virt@127.0.0.1']*/}); //lxc.startEphemeral('ubuntu_template', 'ue0', function(){console.log('cb1', arguments)}, function(){console.log('cb2', arguments)}) router.get('/start/:name', function(req, res, next){ From b3442bf88f5186544f0caa307d6a791371662893 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:21:07 -0500 Subject: [PATCH 06/30] config issue --- lxc.js | 10 +++++++--- package.json | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lxc.js b/lxc.js index 3135f82..e2f1d8c 100644 --- a/lxc.js +++ b/lxc.js @@ -1,6 +1,10 @@ module.exports = function(config){ + var cmd = require('node-cmd'); - var obj = {}; + var sysExec = function(command, callback){ + cmd.get(command, callback) + } +/* var obj = {}; var child = require('child'), sshBind = config.sshBind || false; @@ -34,7 +38,7 @@ module.exports = function(config){ cbClose: function(exitCode){ onClose(exitCode == 0 ? null:exitCode, errors) } }).start(); }; - +*/ obj.create = function(name, template, config, cbComplete, cbData){ sysExec('lxc-create -n '+name+' -t '+template, cbComplete, cbData); @@ -97,7 +101,7 @@ module.exports = function(config){ obj.list = function(cbData){ var output = ''; - sysExec('lxc-ls --fancy', function(data){output+=data}, function(error){ + sysExec('lxc-ls --fancy', function(data){ output = output.split("\n"); var keys = output.splice(0,1)[0].split(/\s+/).slice(0,-1); diff --git a/package.json b/package.json index 79b3cf1..a2505c0 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "redis": "~2.4.2", "child": "0.0.3", "colors": "~1.1.2", - "async": "~1.5.2" + "async": "~1.5.2", + "node-cmd": "~1.1.1" } } From 3002f0148fb792a25344c6f80304d89f76113ba8 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:23:36 -0500 Subject: [PATCH 07/30] config issue --- lxc.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lxc.js b/lxc.js index e2f1d8c..beee9ed 100644 --- a/lxc.js +++ b/lxc.js @@ -1,4 +1,5 @@ module.exports = function(config){ + var obj = {}; var cmd = require('node-cmd'); var sysExec = function(command, callback){ @@ -40,8 +41,8 @@ module.exports = function(config){ }; */ - obj.create = function(name, template, config, cbComplete, cbData){ - sysExec('lxc-create -n '+name+' -t '+template, cbComplete, cbData); + obj.create = function(name, template, config, cbComplete){ + sysExec('lxc-create -n '+name+' -t '+template, cbComplete); }; obj.clone = function(name, base_name, cbComplete, cbData){ From f142b65dae976232afb905aa88dd3c7b91a759aa Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:25:20 -0500 Subject: [PATCH 08/30] config issue --- lxc.js | 2 +- routes/index.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lxc.js b/lxc.js index beee9ed..a791772 100644 --- a/lxc.js +++ b/lxc.js @@ -120,7 +120,7 @@ module.exports = function(config){ info.push(mapOut); } - + console.log('info:', info) cbData(info); }); }; diff --git a/routes/index.js b/routes/index.js index 45f0b1d..fc21a57 100644 --- a/routes/index.js +++ b/routes/index.js @@ -72,9 +72,7 @@ router.get('/info/:name', function(req, res, next){ }); router.get('/list', function(req, res, next) { - lxc.list(function(data){ - res.json(data); - }); + lxc.list(res.json(data)); }); module.exports = router; From 7fa8284c7ef82655c61b7107a1205fbe8b46407b Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:27:01 -0500 Subject: [PATCH 09/30] config issue --- lxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index a791772..3a9a00c 100644 --- a/lxc.js +++ b/lxc.js @@ -3,7 +3,7 @@ module.exports = function(config){ var cmd = require('node-cmd'); var sysExec = function(command, callback){ - cmd.get(command, callback) + cmd.get('unset XDG_SESSION_ID XDG_RUNTIME_DIR; cgm movepid all virt $$; '+command, callback) } /* var obj = {}; var child = require('child'), From 106d9eead44e04ba4976e9a6cddc001c19d0326f Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:27:41 -0500 Subject: [PATCH 10/30] config issue --- routes/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/index.js b/routes/index.js index fc21a57..a0f652f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -72,7 +72,7 @@ router.get('/info/:name', function(req, res, next){ }); router.get('/list', function(req, res, next) { - lxc.list(res.json(data)); + lxc.list(res.json); }); module.exports = router; From d09daf685fcd7cb90268c7a76c085dc9c8815406 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:28:20 -0500 Subject: [PATCH 11/30] config issue --- routes/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routes/index.js b/routes/index.js index a0f652f..45f0b1d 100644 --- a/routes/index.js +++ b/routes/index.js @@ -72,7 +72,9 @@ router.get('/info/:name', function(req, res, next){ }); router.get('/list', function(req, res, next) { - lxc.list(res.json); + lxc.list(function(data){ + res.json(data); + }); }); module.exports = router; From 71430a48588edc28278c2c7f1099b6fd7c307a43 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:29:13 -0500 Subject: [PATCH 12/30] config issue --- lxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index 3a9a00c..cde4ed3 100644 --- a/lxc.js +++ b/lxc.js @@ -103,6 +103,7 @@ module.exports = function(config){ var output = ''; sysExec('lxc-ls --fancy', function(data){ + console.log('info:', data) output = output.split("\n"); var keys = output.splice(0,1)[0].split(/\s+/).slice(0,-1); @@ -120,7 +121,6 @@ module.exports = function(config){ info.push(mapOut); } - console.log('info:', info) cbData(info); }); }; From 20808edd8e7ed80bbf912bb08d0f32e90edb57a1 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:31:44 -0500 Subject: [PATCH 13/30] trying stuff --- lxc.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lxc.js b/lxc.js index cde4ed3..456d066 100644 --- a/lxc.js +++ b/lxc.js @@ -106,9 +106,12 @@ module.exports = function(config){ console.log('info:', data) output = output.split("\n"); + console.log('output:', output) var keys = output.splice(0,1)[0].split(/\s+/).slice(0,-1); + console.log('keys:', keys); keys = keys.map(function(v){return v.toLowerCase()}); output = output.slice(0).splice(1).slice(0,-1); + console.log('output2:', output) var info = []; From df529181423b00ed24d17ad004df78870f9ba98d Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:33:07 -0500 Subject: [PATCH 14/30] trying stuff --- lxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index 456d066..c3266b6 100644 --- a/lxc.js +++ b/lxc.js @@ -105,7 +105,7 @@ module.exports = function(config){ sysExec('lxc-ls --fancy', function(data){ console.log('info:', data) - output = output.split("\n"); + output = data.split("\n"); console.log('output:', output) var keys = output.splice(0,1)[0].split(/\s+/).slice(0,-1); console.log('keys:', keys); From 152e75c79defd17a7ea6d637e35cf9475b2c1e6e Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:36:39 -0500 Subject: [PATCH 15/30] distroy --- lxc.js | 6 +++--- routes/index.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lxc.js b/lxc.js index c3266b6..eabc052 100644 --- a/lxc.js +++ b/lxc.js @@ -49,8 +49,8 @@ module.exports = function(config){ sysExec('lxc-clone -o '+base_name+ ' -n '+name +' -B overlayfs -s', cbComplete, cbData); }; - obj.destroy = function(name, cbComplete, cbData){ - sysExec('lxc-destroy -n '+ name, cbComplete, cbData); + obj.destroy = function(name, callback){ + sysExec('lxc-destroy -n '+ name, callback); }; @@ -60,7 +60,7 @@ module.exports = function(config){ sysExec(cmd, cbComplete, cbData); }; - obj.startEphemeral = function(name, base_name, cbComplete, cbData){ + obj.startEphemeral = function(name, base_name, cbData){ var output = ''; sysExec('lxc-start-ephemeral -o '+base_name+ ' -n '+name +' --union-type overlayfs -d', function(data){output+=data}, function(error){ diff --git a/routes/index.js b/routes/index.js index 45f0b1d..1fbdc3b 100644 --- a/routes/index.js +++ b/routes/index.js @@ -30,7 +30,7 @@ router.get('/start/:name', function(req, res, next){ }); router.get('/live/:template/:name', function(req, res, next){ - lxc.startEphemeral(req.params.name, req.params.template, null, function (data) { + lxc.startEphemeral(req.params.name, req.params.template, function (data) { res.json(data); }); }); @@ -56,7 +56,7 @@ router.get('/clone/:template/:name', function(req, res, next){ }); router.get('/destroy/:name', function(req, res, next){ - lxc.destroy(req.params.name, null, function(data, message){ + lxc.destroy(req.params.name, function(data, message){ if(data){ res.json({status: 500, message: message}); }else{ From 6df6de2ffe986f8fd2c8f9132cb6e78e3bae2660 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:39:48 -0500 Subject: [PATCH 16/30] stop --- lxc.js | 4 ++-- routes/index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lxc.js b/lxc.js index eabc052..274dc73 100644 --- a/lxc.js +++ b/lxc.js @@ -71,8 +71,8 @@ module.exports = function(config){ }); }; - obj.stop = function(name, cbComplete, cbData){ - sysExec('lxc-stop -n '+ name, cbComplete, cbData); + obj.stop = function(name, callback){ + sysExec('lxc-stop -n '+ name, callback); }; diff --git a/routes/index.js b/routes/index.js index 1fbdc3b..6a8e95c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -36,7 +36,7 @@ router.get('/live/:template/:name', function(req, res, next){ }); router.get('/stop/:name', function(req, res, next){ - lxc.stop(req.params.name, null, function(data, message){ + lxc.stop(req.params.name, function(data, message){ if(data){ res.json({status: 500, name: req.params.name, message: message}); }else{ From 8d916eb8ed2e8edf69a0cb2a4bb1811b6eed1903 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:42:19 -0500 Subject: [PATCH 17/30] stop --- lxc.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lxc.js b/lxc.js index 274dc73..354ad33 100644 --- a/lxc.js +++ b/lxc.js @@ -72,6 +72,7 @@ module.exports = function(config){ }; obj.stop = function(name, callback){ + console.log('stop'); sysExec('lxc-stop -n '+ name, callback); }; @@ -103,15 +104,11 @@ module.exports = function(config){ var output = ''; sysExec('lxc-ls --fancy', function(data){ - console.log('info:', data) output = data.split("\n"); - console.log('output:', output) var keys = output.splice(0,1)[0].split(/\s+/).slice(0,-1); - console.log('keys:', keys); keys = keys.map(function(v){return v.toLowerCase()}); output = output.slice(0).splice(1).slice(0,-1); - console.log('output2:', output) var info = []; From bf068177fb8d6eecd272c6f232f371453308a3a6 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 16:50:07 -0500 Subject: [PATCH 18/30] stop --- lxc.js | 6 +++--- routes/index.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lxc.js b/lxc.js index 354ad33..553779b 100644 --- a/lxc.js +++ b/lxc.js @@ -54,10 +54,10 @@ module.exports = function(config){ }; - obj.start = function(name, cbComplete, cbData){ + obj.start = function(name, callback){ var cmd = 'lxc-start --name '+name+' --daemon'; console.log('start cmd\n', cmd, '\n'); - sysExec(cmd, cbComplete, cbData); + sysExec(cmd, callback); }; obj.startEphemeral = function(name, base_name, cbData){ @@ -85,7 +85,7 @@ module.exports = function(config){ sysExec('lxc-unfreeze -n '+name, cbComplete, cbData); }; - obj.info = function(name, cbComplete, cbData){ + obj.info = function(name, cbData){ var output = ''; sysExec('lxc-info -n'+name, function(data){output+=data}, function(error){ diff --git a/routes/index.js b/routes/index.js index 6a8e95c..780f0f1 100644 --- a/routes/index.js +++ b/routes/index.js @@ -7,7 +7,7 @@ var lxc = require('../lxc')({sshBind: false/*['/usr/bin/ssh', 'virt@127.0.0.1']* //lxc.startEphemeral('ubuntu_template', 'ue0', function(){console.log('cb1', arguments)}, function(){console.log('cb2', arguments)}) router.get('/start/:name', function(req, res, next){ - lxc.start(req.params.name, null, function(status, message){ + lxc.start(req.params.name, function(status, message){ if(status){ res.json({status: 500, name: req.params.name, message: message}); }else{ @@ -66,7 +66,7 @@ router.get('/destroy/:name', function(req, res, next){ }); router.get('/info/:name', function(req, res, next){ - lxc.info(req.params.name, null, function(data){ + lxc.info(req.params.name, function(data){ res.json(data); }); }); From b297c1b749af285289cb49343541f1ec50840587 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:09:04 -0500 Subject: [PATCH 19/30] stop --- lxc.js | 17 +++++++++-------- views/index.ejs | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lxc.js b/lxc.js index 553779b..53de663 100644 --- a/lxc.js +++ b/lxc.js @@ -3,6 +3,7 @@ module.exports = function(config){ var cmd = require('node-cmd'); var sysExec = function(command, callback){ + console.log('sysExec --', command) cmd.get('unset XDG_SESSION_ID XDG_RUNTIME_DIR; cgm movepid all virt $$; '+command, callback) } /* var obj = {}; @@ -60,14 +61,14 @@ module.exports = function(config){ sysExec(cmd, callback); }; - obj.startEphemeral = function(name, base_name, cbData){ + obj.startEphemeral = function(name, base_name, callback){ var output = ''; sysExec('lxc-start-ephemeral -o '+base_name+ ' -n '+name +' --union-type overlayfs -d', function(data){output+=data}, function(error){ - if(output.match("doesn't exist.")) return cbData({status: 500, error: "doesn't exist."}); - if(output.match("already exists.")) return cbData({status: 500, error: "already exists"}); - if(output.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)) return cbData({status: 200, state:'RUNNING', ip: output.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)[0]}); - cbData({'?': '?', data: output, name: name, base_name: base_name}); + if(output.match("doesn't exist.")) return callback({status: 500, error: "doesn't exist."}); + if(output.match("already exists.")) return callback({status: 500, error: "already exists"}); + if(output.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)) return callback({status: 200, state:'RUNNING', ip: output.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)[0]}); + callback({'?': '?', data: output, name: name, base_name: base_name}); }); }; @@ -85,18 +86,18 @@ module.exports = function(config){ sysExec('lxc-unfreeze -n '+name, cbComplete, cbData); }; - obj.info = function(name, cbData){ + obj.info = function(name, callback){ var output = ''; sysExec('lxc-info -n'+name, function(data){output+=data}, function(error){ - if(output.match("doesn't exist")) return cbData({state: 'NULL'}); + if(output.match("doesn't exist")) return callback({state: 'NULL'}); var info = {}; output = output.replace(/\suse/ig, '').replace(/\sbytes/ig, '').split("\n").slice(0,-1); for(var i in output){ var temp = output[i].split(/\:\s+/); info[temp[0].toLowerCase().trim()] = temp[1].trim(); } - cbData(info); + callback(info); }); }; diff --git a/views/index.ejs b/views/index.ejs index 2ff58d5..d07ba87 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -26,7 +26,7 @@ if(data.state === 'RUNNING'){ var url = '//'+data.name+'.vm42.us'; data.url = ''+url+''; - }else if( data.state !== "RUNNING" && data.name.match(/_template/) ){ + }else if( data.state !== "RUNNING" && data.name.match(/\w\w/) ){ data.clone = $('#cloneFormTemplate').html(); } From cc5ea8be063288a1b27daa587e20d14b972b6823 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:13:53 -0500 Subject: [PATCH 20/30] stop --- lxc.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lxc.js b/lxc.js index 53de663..af7d2d5 100644 --- a/lxc.js +++ b/lxc.js @@ -3,7 +3,7 @@ module.exports = function(config){ var cmd = require('node-cmd'); var sysExec = function(command, callback){ - console.log('sysExec --', command) + console.log('sysExec: ', command, '||| callback:' callback) cmd.get('unset XDG_SESSION_ID XDG_RUNTIME_DIR; cgm movepid all virt $$; '+command, callback) } /* var obj = {}; @@ -101,18 +101,15 @@ module.exports = function(config){ }); }; - obj.list = function(cbData){ - - var output = ''; + obj.list = function(callback){ sysExec('lxc-ls --fancy', function(data){ - - output = data.split("\n"); + var output = data.split("\n"); var keys = output.splice(0,1)[0].split(/\s+/).slice(0,-1); + var info = []; + keys = keys.map(function(v){return v.toLowerCase()}); output = output.slice(0).splice(1).slice(0,-1); - var info = []; - for (var i in output) { @@ -122,7 +119,7 @@ module.exports = function(config){ info.push(mapOut); } - cbData(info); + callback(info); }); }; From 8208f61f5a81955b841310dbabead2dff9180f4b Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:14:10 -0500 Subject: [PATCH 21/30] stop --- lxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index af7d2d5..4829569 100644 --- a/lxc.js +++ b/lxc.js @@ -3,7 +3,7 @@ module.exports = function(config){ var cmd = require('node-cmd'); var sysExec = function(command, callback){ - console.log('sysExec: ', command, '||| callback:' callback) + console.log('sysExec: ', command, '||| callback:', callback) cmd.get('unset XDG_SESSION_ID XDG_RUNTIME_DIR; cgm movepid all virt $$; '+command, callback) } /* var obj = {}; From 57fabcb24e7469a7558edf9fe84c774689f23822 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:16:13 -0500 Subject: [PATCH 22/30] stop --- lxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index 4829569..16e195e 100644 --- a/lxc.js +++ b/lxc.js @@ -89,7 +89,7 @@ module.exports = function(config){ obj.info = function(name, callback){ var output = ''; - sysExec('lxc-info -n'+name, function(data){output+=data}, function(error){ + sysExec('lxc-info -n '+name, function(data){ if(output.match("doesn't exist")) return callback({state: 'NULL'}); var info = {}; output = output.replace(/\suse/ig, '').replace(/\sbytes/ig, '').split("\n").slice(0,-1); From a7b2aea9bbb15295a2ea8b7ec7a5937dc952e8ba Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:17:07 -0500 Subject: [PATCH 23/30] stop --- lxc.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index 16e195e..8981492 100644 --- a/lxc.js +++ b/lxc.js @@ -3,7 +3,7 @@ module.exports = function(config){ var cmd = require('node-cmd'); var sysExec = function(command, callback){ - console.log('sysExec: ', command, '||| callback:', callback) + // console.log('sysExec: ', command, '||| callback:', callback) cmd.get('unset XDG_SESSION_ID XDG_RUNTIME_DIR; cgm movepid all virt $$; '+command, callback) } /* var obj = {}; @@ -90,6 +90,7 @@ module.exports = function(config){ var output = ''; sysExec('lxc-info -n '+name, function(data){ + console.log(data) if(output.match("doesn't exist")) return callback({state: 'NULL'}); var info = {}; output = output.replace(/\suse/ig, '').replace(/\sbytes/ig, '').split("\n").slice(0,-1); From 4071ed22d7f78528e8e72348b3a1c4be925af18e Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:18:15 -0500 Subject: [PATCH 24/30] stop --- lxc.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lxc.js b/lxc.js index 8981492..8d339e4 100644 --- a/lxc.js +++ b/lxc.js @@ -91,11 +91,11 @@ module.exports = function(config){ var output = ''; sysExec('lxc-info -n '+name, function(data){ console.log(data) - if(output.match("doesn't exist")) return callback({state: 'NULL'}); + if(data.match("doesn't exist")) return callback({state: 'NULL'}); var info = {}; - output = output.replace(/\suse/ig, '').replace(/\sbytes/ig, '').split("\n").slice(0,-1); - for(var i in output){ - var temp = output[i].split(/\:\s+/); + data = data.replace(/\suse/ig, '').replace(/\sbytes/ig, '').split("\n").slice(0,-1); + for(var i in data){ + var temp = data[i].split(/\:\s+/); info[temp[0].toLowerCase().trim()] = temp[1].trim(); } callback(info); From 0cec756e4495c987fa268e4dd7b19f2e49021212 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:20:00 -0500 Subject: [PATCH 25/30] stop --- lxc.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lxc.js b/lxc.js index 8d339e4..a89af17 100644 --- a/lxc.js +++ b/lxc.js @@ -64,11 +64,11 @@ module.exports = function(config){ obj.startEphemeral = function(name, base_name, callback){ var output = ''; - sysExec('lxc-start-ephemeral -o '+base_name+ ' -n '+name +' --union-type overlayfs -d', function(data){output+=data}, function(error){ - if(output.match("doesn't exist.")) return callback({status: 500, error: "doesn't exist."}); - if(output.match("already exists.")) return callback({status: 500, error: "already exists"}); - if(output.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)) return callback({status: 200, state:'RUNNING', ip: output.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)[0]}); - callback({'?': '?', data: output, name: name, base_name: base_name}); + sysExec('lxc-start-ephemeral -o '+base_name+ ' -n '+name +' --union-type overlayfs -d', function(data){ + if(data.match("doesn't exist.")) return callback({status: 500, error: "doesn't exist."}); + if(data.match("already exists.")) return callback({status: 500, error: "already exists"}); + if(data.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)) return callback({status: 200, state:'RUNNING', ip: data.match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/)[0]}); + callback({'?': '?', data: data, name: name, base_name: base_name}); }); }; From c69115f08e844fe713b1950325118fc1c4357cf4 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:22:25 -0500 Subject: [PATCH 26/30] stop --- lxc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lxc.js b/lxc.js index a89af17..7d85f87 100644 --- a/lxc.js +++ b/lxc.js @@ -73,7 +73,7 @@ module.exports = function(config){ }; obj.stop = function(name, callback){ - console.log('stop'); + console.log('stop', name); sysExec('lxc-stop -n '+ name, callback); }; @@ -90,7 +90,7 @@ module.exports = function(config){ var output = ''; sysExec('lxc-info -n '+name, function(data){ - console.log(data) + console.log('info', name, data) if(data.match("doesn't exist")) return callback({state: 'NULL'}); var info = {}; data = data.replace(/\suse/ig, '').replace(/\sbytes/ig, '').split("\n").slice(0,-1); From d7bcffa38e884fff3e0a188beb41c2e37690c38c Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:23:50 -0500 Subject: [PATCH 27/30] stop --- routes/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/index.js b/routes/index.js index 780f0f1..138ef40 100644 --- a/routes/index.js +++ b/routes/index.js @@ -56,9 +56,9 @@ router.get('/clone/:template/:name', function(req, res, next){ }); router.get('/destroy/:name', function(req, res, next){ - lxc.destroy(req.params.name, function(data, message){ + lxc.destroy(req.params.name, function(data){ if(data){ - res.json({status: 500, message: message}); + res.json({status: 500, message: data}); }else{ res.json({status: 200}); } From ed7d0972acb02a5df13c623edbe1f34ed7e90e13 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:27:56 -0500 Subject: [PATCH 28/30] stop --- lxc.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lxc.js b/lxc.js index 7d85f87..5004fce 100644 --- a/lxc.js +++ b/lxc.js @@ -51,10 +51,11 @@ module.exports = function(config){ }; obj.destroy = function(name, callback){ - sysExec('lxc-destroy -n '+ name, callback); + sysExec('lxc-destroy -n '+ name, function(data){ + callback(data.match(/Destroyed container u1-sdfwefwe\n/)) + }); }; - obj.start = function(name, callback){ var cmd = 'lxc-start --name '+name+' --daemon'; console.log('start cmd\n', cmd, '\n'); From ec07ce2ee0f01ea13b178cabf6eea2290c8f7cca Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:28:55 -0500 Subject: [PATCH 29/30] stop --- lxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index 5004fce..1278f39 100644 --- a/lxc.js +++ b/lxc.js @@ -52,7 +52,7 @@ module.exports = function(config){ obj.destroy = function(name, callback){ sysExec('lxc-destroy -n '+ name, function(data){ - callback(data.match(/Destroyed container u1-sdfwefwe\n/)) + callback(!data.match(/Destroyed container u1-sdfwefwe\n/)) }); }; From 74aea9100fdd8957f1179f613a74942a52aad4bc Mon Sep 17 00:00:00 2001 From: william Date: Fri, 29 Jan 2016 17:29:43 -0500 Subject: [PATCH 30/30] stop --- lxc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc.js b/lxc.js index 1278f39..45a8fc8 100644 --- a/lxc.js +++ b/lxc.js @@ -52,7 +52,7 @@ module.exports = function(config){ obj.destroy = function(name, callback){ sysExec('lxc-destroy -n '+ name, function(data){ - callback(!data.match(/Destroyed container u1-sdfwefwe\n/)) + callback(!data.match(/Destroyed container/)) }); };