~nskaggs/juju-ci-tools/add-assess-terms

550 by Curtis Hovey
Added script to cleanup manual provider tests.
1
#!/bin/bash
2
1539 by Curtis Hovey
Cleanup systemd machines after manual.
3
EXITCODE=0
4
550 by Curtis Hovey
Added script to cleanup manual provider tests.
5
ips="$@"
6
for ip in $ips; do
1147.1.1 by Martin Packman
Fix quoting in remove manual script and add new uninstall handling
7
    ssh -i $JUJU_HOME/staging-juju-rsa ubuntu@$ip <<"EOT"
550 by Curtis Hovey
Added script to cleanup manual provider tests.
8
#!/bin/bash
9
set -ux
1277 by Curtis Hovey
State when cleaning is happening..
10
1539 by Curtis Hovey
Cleanup systemd machines after manual.
11
DIRTY=0
1147.1.2 by Martin Packman
Attempt two at making the manual cleanup script sane
12
JUJU_DIR="/var/lib/juju"
13
DUMMY_DIR="/var/run/dummy-sink"
1539 by Curtis Hovey
Cleanup systemd machines after manual.
14
15
echo "Cleaning manual machine"
16
17
# This is left by the test.
18
if [[ -d $DUMMY_DIR ]]; then
19
    sudo rm -r $DUMMY_DIR
20
fi
21
1580.1.1 by Curtis Hovey
Clear the juju logs when cleaning manual hosts.
22
# Juju always leaves logs behind for debuging, and they are already collected.
23
sudo rm /var/log/juju/*.log || true
24
1539 by Curtis Hovey
Cleanup systemd machines after manual.
25
# Juju must cleanup these procs.
1147.1.3 by Martin Packman
Tweak to ps command suggested by abentley in review
26
if ps -f -C jujud; then
1539 by Curtis Hovey
Cleanup systemd machines after manual.
27
    DIRTY=1
28
    echo "ERROR manual-provider: jujud left running."
1147.1.2 by Martin Packman
Attempt two at making the manual cleanup script sane
29
    sudo touch $JUJU_DIR/uninstall-agent
550 by Curtis Hovey
Added script to cleanup manual provider tests.
30
    sudo killall -SIGABRT jujud
31
fi
1539 by Curtis Hovey
Cleanup systemd machines after manual.
32
if ps -f -C mongod; then
33
    DIRTY=1
34
    echo "ERROR manual-provider: mongod left running."
35
    sudo killall -9 mongod || true
36
fi
37
if [[ -d /etc/systemd/system ]]; then
38
    found=$(ls /etc/systemd/system/juju*)
39
    if [[ -n $found ]]; then
40
        DIRTY=1
41
        echo "ERROR manual-provider: systemd services left behind."
42
        for service_path in $found; do
43
            service=$(basename $service_path)
44
            sudo systemctl stop --force $service || true
45
            sudo systemctl disable $service || true
46
            sudo rm $service_path || true
47
        done
48
    fi
49
fi
50
if [[ -d /etc/init ]]; then
51
    found=$(find /etc/init -name 'juju*' -print)
52
    if [[ -n $found ]]; then
53
        DIRTY=1
54
        echo "ERROR manual-provider: upstart services left behind."
55
        sudo find /etc/init -name 'juju*' -delete || true
56
    fi
57
fi
550 by Curtis Hovey
Added script to cleanup manual provider tests.
58
if [[ -d $JUJU_DIR ]]; then
1539 by Curtis Hovey
Cleanup systemd machines after manual.
59
    DIRTY=1
60
    echo "ERROR manual-provider: $JUJU_DIR left behind."
550 by Curtis Hovey
Added script to cleanup manual provider tests.
61
    sudo rm -r $JUJU_DIR
62
fi
1277 by Curtis Hovey
State when cleaning is happening..
63
echo "Cleaning completed"
1539 by Curtis Hovey
Cleanup systemd machines after manual.
64
exit $DIRTY
550 by Curtis Hovey
Added script to cleanup manual provider tests.
65
EOT
1539 by Curtis Hovey
Cleanup systemd machines after manual.
66
    if [[ $? != 0 ]];then
67
        EXITCODE=1
68
    fi
550 by Curtis Hovey
Added script to cleanup manual provider tests.
69
done
1539 by Curtis Hovey
Cleanup systemd machines after manual.
70
71
exit $EXITCODE