Laphatize
(Pranav Ramesh)
January 9, 2023, 7:56pm
1
I have a shell script named containerLaunch.sh
that looks like this
#!/bin/bash
echo "Creating container.."
lxc launch ubuntu:18.04 $1
lxc exec $1 -- sudo --user ubuntu --login
I deploy this script using Node.js via the exec function:
var containerName = req.query.name;
const myShellScript = exec('sh ./containerLaunch.sh ' + containerName);
myShellScript.stdout.on('data', (data)=>{
console.log(data);
});
myShellScript.stderr.on('data', (data)=>{
console.error(data);
});
But, it simply runs the first echo command and not any of the other lxc commands.
Interestingly, directly running the shell file by doing sh ./containerLaunch.sh test
, it seems to work.
What is causing this and how do I fix it?
turtle0x1
(Turtle0x1)
January 10, 2023, 9:47am
2
Maybe take a look at the link below, I cant confirm but I expect its a similar problem.
You should think about using a “real” client library if your using node and not executing adhoc scripts
Ok.
I know.
This is very weird and very likely to have nothing to do with lxc/lxd at all.
I am asking here exactly because it is very strange and insight from knowledgeable people could make the difference.
I am trying to write a python script to automatize container handling.
It generally works quite well but there’s ONE command that hangs completely if/when used under PyCharm (it works perfectly fine if run from the command line).
this minimal example:
import subprocess
image = 'images…
k4my4b
January 10, 2023, 11:21am
3
Beauty of LXD, or rather one of them, is that it has a REST API .
And luckily for you there are at least a couple of NodeJS API clients already available.
Example from the ts-lxd github page:
“The following example connects to the local LXC instance and launches a new container.”
import lxd from "ts-lxd";
const client = lxd();
(async () => {
const container = await client.createContainer("myContainer", "ubuntu");
await container.start();
console.log("Started " + container.name());
})();
tomp
(Thomas Parrott)
January 10, 2023, 2:47pm
4
You probably need to close stdin as lxc launch
will try and read the instance config from stdin.