forked from worph/casa-img
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
143 lines (111 loc) · 4.59 KB
/
entrypoint.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
set -Eeuo pipefail
info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "${1:-}" "\E[0m\n"; }
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: ${1:-}" "\E[0m\n" >&2; }
warn () { printf "%b%s%b" "\E[1;31m❯ " "Warning: ${1:-}" "\E[0m\n" >&2; }
trap 'error "Status $? while: $BASH_COMMAND (line $LINENO/$BASH_LINENO)"' ERR
[ ! -f "/root/entrypoint.sh" ] && error "Script must run inside Docker container!" && exit 11
[ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12
echo "❯ Starting CasaOS for Docker v$(</run/version)..."
echo "❯ For support visit https://github.com/dockur/casa/issues"
if [ ! -S /var/run/docker.sock ]; then
error "Docker socket is missing? Please bind /var/run/docker.sock in your compose file." && exit 13
fi
net="casa-net"
export REF_NET="$net"
export REF_SEPARATOR="-"
if ! docker network inspect "$net" &>/dev/null; then
if ! docker network create --driver=bridge --subnet="10.22.0.0/16" "$net" >/dev/null; then
error "Failed to create network '$net'!" && exit 14
fi
if ! docker network inspect "$net" &>/dev/null; then
error "Network '$net' does not exist?" && exit 15
fi
fi
target=$(hostname -s)
if ! docker inspect "$target" &>/dev/null; then
error "Failed to find a container with name: '$target'!" && exit 16
fi
resp=$(docker inspect "$target")
network=$(echo "$resp" | jq -r '.[0].NetworkSettings.Networks["casa-net"]')
if [ -z "$network" ] || [[ "$network" == "null" ]]; then
if ! docker network connect "$net" "$target"; then
error "Failed to connect container to network '$net'!" && exit 17
fi
fi
mount=$(echo "$resp" | jq -r '.[0].Mounts[] | select(.Destination == "/DATA").Source')
if [ -z "$mount" ] || [[ "$mount" == "null" ]] || [ ! -d "/DATA" ]; then
error "You did not bind the /DATA folder!" && exit 18
fi
# Convert Windows paths to Linux path
if [[ "$mount" == *":\\"* ]]; then
mount="${mount,,}"
mount="${mount//\\//}"
mount="//${mount/:/}"
fi
if [[ "$mount" != "/"* ]]; then
error "Please bind the /DATA folder to an absolute path!" && exit 19
fi
# Mirror external folder to local filesystem
if [[ "$mount" != "/DATA" ]]; then
mkdir -p "$mount"
rm -rf "$mount"
ln -s /DATA "$mount"
fi
export DATA_ROOT="$mount"
# Create directories
mkdir -p /DATA/AppData/casaos
mkdir -p /var/log
touch /var/log/casaos-gateway.log
touch /var/log/casaos-app-management.log
touch /var/log/casaos-user-service.log
touch /var/log/casaos-mesage-bus.log
touch /var/log/casaos-local-storage.log
touch /var/log/casaos-main.log
# Start the Gateway service and redirect stdout and stderr to the log files
./casaos-gateway > /var/log/casaos-gateway.log 2>&1 &
# Wait for the Gateway service to start
while [ ! -f /var/run/casaos/management.url ]; do
info "Waiting for the Management service to start..."
sleep 1
done
while [ ! -f /var/run/casaos/static.url ]; do
info "Waiting for the Gateway service to start..."
sleep 1
done
# Start the MessageBus service and redirect stdout and stderr to the log files
./casaos-message-bus > /var/log/casaos-message-bus.log 2>&1 &
# Wait for the Gateway service to start
while [ ! -f /var/run/casaos/message-bus.url ]; do
info "Waiting for the Message service to start..."
sleep 1
done
# Start the Main service and redirect stdout and stderr to the log files
./casaos-main > /var/log/casaos-main.log 2>&1 &
# Wait for the Main service to start
while [ ! -f /var/run/casaos/casaos.url ]; do
info "Waiting for the Main service to start..."
sleep 1
done
# Start the LocalStorage service and redirect stdout and stderr to the log files
./casaos-local-storage > /var/log/casaos-local-storage.log 2>&1 &
# wait for /var/run/casaos/routes.json to be created and contains local_storage
# Wait for /var/run/casaos/routes.json to be created and contains local_storage
while [ ! -f /var/run/casaos/routes.json ] || ! grep -q "local_storage" /var/run/casaos/routes.json; do
info "Waiting for /var/run/casaos/routes.json to be created and contains local_storage..."
sleep 1
done
# Start the AppManagement service and redirect stdout and stderr to the log files
./casaos-app-management > /var/log/casaos-app-management.log 2>&1 &
# Start the UserService service and redirect stdout and stderr to the log files
./casaos-user-service > /var/log/casaos-user-service.log 2>&1 &
./register-ui-events.sh
trap - ERR
# Tail the log files to keep the container running and to display the logs in stdout
tail -f \
/var/log/casaos-gateway.log \
/var/log/casaos-app-management.log \
/var/log/casaos-user-service.log \
/var/log/casaos-message-bus.log \
/var/log/casaos-local-storage.log \
/var/log/casaos-main.log