-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathssl_renew.sh
51 lines (46 loc) · 1.79 KB
/
ssl_renew.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
#!/bin/bash
# please run in with sudo command
# removing any servers
docker-compose -f docker-compose.dev.yml down
docker-compose -f docker-compose.prod.yml down
echo y | docker container prune
echo "generating ssh if expired. please make sure port 80 is open and not used by any server.."
export $(cat .env | xargs)
stopped_id=null
for id in $(docker ps -q); do
if [[ $(docker port "${id}") == *"80"* ]]; then
echo "stopping container ${id}"
docker stop "${id}"
stopped_id=$id
break
fi
done
domains=("portofolio.orbitskomputer.com")
for i in "${domains[@]}"; do
echo "check $i is exist in ssl directory?"
if [ -d "../ssl/main/archive/$i" ]; then
# check if exist in directoriy live too
if [ ! -d "../ssl/main/live/$i" ]; then
echo "not exist in live directory, removing from archive"
rm -r -f ../ssl/main/archive/$i
rm -r -f ../ssl/main/live/$i
fi
echo "exist in archive directory, skipping request certificate..";
fi
# check if directory archive exist
if [ ! -d "../ssl/main/archive/$i" ]; then
echo "requesting certificate for $i";
# request a certificate
docker run -it -v "/$(pwd)/../ssl/main:/etc/letsencrypt" -p 80:80 certbot/certbot certonly --standalone --email [email protected] --agree-tos --no-eff-email -d $i --keep-until-expiring
fi
sleep 3;
done
sleep 5;
echo "renew all ssl certificates...";
docker run -v "/$(pwd)/../ssl/main:/etc/letsencrypt" -p 80:80 \
certbot/certbot renew --standalone --email [email protected] --agree-tos --no-eff-email
# check if stopped_id not null
if [[ $stopped_id != null ]]; then
echo "removing container ${stopped_id}"
docker start "${stopped_id}" # resuming the processes that use port 80
fi