-
Notifications
You must be signed in to change notification settings - Fork 4
/
reset-db.sh
executable file
·60 lines (46 loc) · 1.99 KB
/
reset-db.sh
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
#!/bin/bash
echo "⚠️ THIS WILL RESET THE DATABASE AND WIPE OUT ALL DATA ⚠️"
read -p "Are you sure? (Y/N): " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "Bye... 👋"
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
echo "Flushing the database..."
source ./backend/venv/bin/activate && echo yes | python ./backend/manage.py flush
echo "Scaling down all zane-ops services..."
services=$(docker service ls --filter label=zane-managed=true --format "{{.Name}}")
for service in $services
do
docker service scale $service=0
done
echo "Waiting for 5 seconds for the services to to finish scaling down..."
sleep 5
echo "Deleting services..."
docker service rm $(docker service ls -q --filter label=zane-managed=true) 2>/dev/null
echo "Deleting volumes..."
docker volume rm $(docker volume ls -q --filter label=zane-managed=true) 2>/dev/null
echo "Detaching networks from the proxy..."
zane_networks_ids=$(docker network ls -q --filter label=zane-managed=true --format '{{.ID}}')
network_options=""
while read -r net_id;
do
network_options+=" --network-rm $net_id"
done <<< "$zane_networks_ids"
service_name="zane_zane-proxy"
echo "docker service update $network_options zane_zane-proxy"
if [ -n "$network_options" ]; then
# Update the service with all networks
docker service update $network_options $service_name
fi
echo "Deleting networks..."
docker network rm $(docker network ls -q --filter label=zane-managed=true) 2>/dev/null
echo "Resetting caddy config..."
sed -i'.bak' "s#{{ZANE_HOST}}#app.zaneops.local#g" ./docker/proxy/default-caddy-config.json
curl "http://localhost:2019/load" \
-H "Content-Type: application/json" \
-d @docker/proxy/default-caddy-config.json
rm ./docker/proxy/default-caddy-config.json
mv ./docker/proxy/default-caddy-config.json.bak ./docker/proxy/default-caddy-config.json
echo "Recreating the superuser..."
source ./backend/venv/bin/activate && python ./backend/manage.py createsuperuser