Remove Juju Local Environment Cleanly

UPDATE 2015-01-28: Now taking into account recent changes to Juju 1.20+

If you’re frequently hacking on¬†Juju¬†source code or just creating and destroying local environments often, you may find the following snippet I came up with handy.

It’s supposed to be run as root, like sudo cleanup-juju (assuming it’s somewhere in your ‘$PATH’ and it’s executable). Just change LOCAL_ENV=localenv to whatever your local environment name is (from $HOME/.juju/environments.yaml – usually local) and run it. Twice, if needed (when mongodb and/or jujud agents are busy), to clean up:

  • Any leftover gocheck or mgo test directories in /tmp (these tend to accumulate over time and waste space)
  • Juju run-time temporary directories (e.g. /tmp/juju-worker-deployer<random-number>/)
  • Mongo socket files created by mongod run from juju tests (port other than the default 27017)
  • Old-style upstart “auto start” configuration (in juju 1.17 and later we use user upstart jobs for that)
  • Any juju or juju-lxc logs
  • Any lxc containers created by juju for that local environment
  • The .jenv file of the environment itself
  • Kill any mongod or jujud processes related to the local environment (for this to work it’s important you pick a unique name for your environment, so that ps xa | grep <envname> does not return processes not belonging to the environment – i.e. “local” is a bit too generic, I use “localenv”)

I hope you find this useful, especially if your juju destroy-environment localenv fails for some reason to clean up after itself, or if juju bootstrap fails and leaves the environment in a bad state.


Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.