-
Notifications
You must be signed in to change notification settings - Fork 29
/
juju-clean
executable file
·71 lines (60 loc) · 2.18 KB
/
juju-clean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
#
# Copyright 2014 Marco Ceppi <[email protected]>
#
# 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"