question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

container.execute() not working

See original GitHub issue

I have flask application (flask + socketio + gunicorn), and pylxd not working correctly on it. Problem in container.execute() method.

For example

print(0)
container.execute(['ls'])
print(1)
container.execute(['cd', '/var/www/html'])
print(2)
container.execute(['service', 'nginx', 'restart'])
print(3)

Output: 0

Please help me 😦

pylxd = 2.2.10 lxd = 3.18

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
ajkavanaghcommented, Oct 28, 2019

Thanks for the update. The warnings are because LXD has grown some new attributes on some of the models, and pylxd is unaware of them. You can silence them by setting PYLXD_WARNINGS=‘none’ in the environment before running the app which loads pylxd.

This was added in #361 – by default one warning is printed for each attribute known about; there is an ‘always’ setting which prints the warning for every subsequent model load.

I think you are probably hitting #379 which I’m looking at. An (ugly) work-around is to use subprocess.Popen and just run lxc exec directly through that; but this only works if it is on the same machine and the user has the same permissions as the pylxd user that is being used.

I may provide that as an alternative exec method, but it has the above significant issues.

0reactions
ajkavanaghcommented, Jul 15, 2020

Popen(...) by default connects the stdin, stdout and stderr to the parent process’ (i.e. your script’s) stdin / stdout. Therefore, the print("OKKKKKK") has no where to go. So if the command is still running on the container, then it is still holding the stdout and thus the print in the script will be buffered. What you really want to do is let the script run in the container that starts the service as a daemon and then exits. At least, I suspect that is what is going on.

You only need to use Popen(..) if you want to communicate with the process as it is running. i.e. send it input, etc. Then you use the .communicate() method after setting up the stdin, stdout, etc. to PIPEs to do that communication. If you are running one-shot commands, it’s easier to use subprocess.check_call() and friends.

Read more comments on GitHub >

github_iconTop Results From Across the Web

docker - Container is not running - Stack Overflow
To keep the container running in the background, try to run it with --detach (or -d ) argument. Save this answer.
Read more >
How to Fix and Debug Docker Containers Like a Superhero
Container errors are tricky to diagnose, but some investigative magic works wonders. Read along to learn how to debug Docker containers.
Read more >
How To Use docker exec to Run Commands in ... - DigitalOcean
When developing or deploying containers you'll often need to look inside a running container to inspect its current state or debug a problem...
Read more >
How can I run a docker exec command inside a ... - Edureka
the docker command does not exist ... you can run any command in a running container just knowing its ID (or name):
Read more >
Troubleshoot Cloud Run issues
Deployment errors. This section lists issues that you might encounter with deployment and provides suggestions for how to fix each of them. Container...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found