This repository has been archived by the owner on May 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
openvidu_coturn
executable file
·86 lines (76 loc) · 2.33 KB
/
openvidu_coturn
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
echo_help () {
echo "coturn help"
echo "Examples: "
echo " - ./openvidu_coturn --start"
echo " Start coturn service"
echo ""
echo " - ./openvidu_coturn --stop"
echo " Stop coturn service"
echo ""
echo " - ./openvidu_coturn --restart"
echo " Restart coturn service"
echo ""
echo " - ./openvidu_coturn --logs"
echo " Follow all logs"
echo ""
}
fatal_error() {
printf "\n =======¡ERROR!======="
printf "\n %s" "$1"
printf "\n"
exit 1
}
prepare_config_files() {
echo "Preparing configuration files..."
# Load environment variables
export $(grep -v '^#' .env | xargs)
# Check all required variables
[[ -n "${LETSENCRYPT_EMAIL}" ]] || fatal_error "LETSENCRYPT_EMAIL must be defined"
[[ -n "${COTURN_DOMAIN_NAME}" ]] || fatal_error "COTURN_DOMAIN_NAME must be defined"
[[ -n "${TURN_USERNAME}" ]] || fatal_error "TURN_USERNAME must be defined"
[[ -n "${TURN_PASSWORD}" ]] || fatal_error "TURN_PASSWORD must be defined"
}
# Dependencies check
if ! command -v docker &> /dev/null
then
echo "'docker' could not be found. You need to install 'docker' and 'docker-compose'"
exit 1
fi
if ! command -v docker-compose &> /dev/null
then
echo "'docker-compose' could not be found. You need to install 'docker' and 'docker-compose'"
exit 1
fi
OPTION=$1
if [[ "${OPTION}" == "--start" ]]; then
echo ""
echo "==========================================="
echo "Starting Coturn"
echo "==========================================="
echo ""
prepare_config_files || exit 1
docker-compose up -d certbot || exit 1
until [ -f "${PWD}"/certbot/etc/letsencrypt/live/"${COTURN_DOMAIN_NAME}"/cert.pem ]
do
sleep 5
done
docker-compose up -d coturn || exit 1
docker-compose logs -f
elif [[ "${OPTION}" == "--stop" ]]; then
docker-compose down || exit 1
elif [[ "${OPTION}" == "--restart" ]]; then
docker-compose down || exit 1
prepare_config_files || exit 1
docker-compose up -d certbot || exit 1
until [ -f "${PWD}"/certbot/etc/letsencrypt/live/"${COTURN_DOMAIN_NAME}"/cert.pem ]
do
sleep 5
done
docker-compose up -d coturn || exit 1
docker-compose logs -f
elif [[ "${OPTION}" == "--logs" ]]; then
docker-compose logs -f
else
echo_help
fi