Python chroot and exit chroot

I know this has been written a few time online, but the last time I needed to read up on it, it took a little long to find the answer. What I wanted to do was to chroot in to a new root, then exit that chroot via python . Below we have my current working directory that is /root , take a look at what we have in the directory:

Clearing Varnish Cache without Restart

There has been a number of times when I’ve needed to clear the Varnish caching server’s cache, but had no clue how to do this. This resulted in me restarting Varnish, which really wasn’t needed. The easiest way to clear the Varnish cache (without restarting) is by using the varnishadm command line tool: varnishadm -T 127.0.0.1:6082 url.purge . The man page for varnishd shows a number of command which can be used with varnishadm , but the one we need is url.

Python Running System Command

So there are a few ways to run system command using python, but I tend to find the below approach the easiest to use and has error handling. First off I would create a function rather than running the commands over and over: import subprocess def run(command): '''takes a string command and hands back a subprocess object''' process = subprocess.Popen(command.split(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) process.wait() return process The function itself is pretty small and makes use of the subprocess library .