Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| #!/bin/bash | |
| # | |
| # Copyright 2014 Marco Ceppi <marco@ceppi.net> | |
| # | |
| # juju-clean is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # juju-clean is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # For a full copy of the GNU General Public License, see | |
| # <http://www.gnu.org/licenses/>. | |
| set -e | |
| JUJU_ENV=$1 | |
| JUJU_HOME=${JUJU_HOME:-~/.juju} | |
| if [ ! "$JUJU_ENV" ]; then | |
| echo "Please run juju clean <environment>" | |
| exit 1 | |
| fi | |
| if [ "$JUJU_ENV" == "--description" ]; then | |
| echo "Destroy environment and clean any remaining files" | |
| exit 0 | |
| fi | |
| if [ "$JUJU_ENV" == "--help" ]; then | |
| echo "juju clean [JUJU_ENV]" | |
| echo "" | |
| echo "Destroy the [JUJU_ENV] and remove any .jenv or local directories associated with the environment" | |
| exit 0 | |
| fi | |
| echo "Destroying '$JUJU_ENV' environment" >&2 | |
| juju destroy-environment -y $JUJU_ENV >/dev/null 2>&1 || true | |
| juju destroy-environment --force -y $JUJU_ENV >/dev/null 2>&1 || true | |
| echo "Removing any extra environment files in '${JUJU_HOME}'" >&2 | |
| rm -f ~/${JUJU_HOME}/environments/$JUJU_ENV.jenv | |
| rm -rf ~/${JUJU_HOME}/$JUJU_ENV || true | |
| echo "Checking for errors with local provider" >&2 | |
| echo "Stopping juju daemons" >&2 | |
| for jujudaemon in $(sudo initctl list | grep juju | cut -d ' ' -f 1) | |
| do | |
| sudo stop ${jujudaemon} || true | |
| done | |
| echo "Destroying juju template containers" >&2 | |
| for container in $(sudo lxc-ls | grep -e "^juju.*template$" ) | |
| do | |
| sudo lxc-stop --name ${container} && sudo lxc-destroy --name ${container} || true | |
| done | |
| echo "Cleaning local providor files" >&2 | |
| sudo rm /etc/init/juju-* || true | |
| sudo rm /etc/rsyslog.d/25-juju* || true | |
| sudo rm -rf /var/lib/juju/containers/${USER}-* || true | |
| sudo rm -rf /var/lib/juju/locks/* || true | |
| echo "Cleaning lxc files" >&2 | |
| sudo rm -rf /var/cache/lxc/cloud-* || true | |
| sudo rm /var/lib/lxc/juju-* || true | |
| sudo rm /etc/lxc/auto/${USER}-* || true | |
| echo "Clean and ready for bootstrap" |