-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinstall_kupiki_admin.sh
183 lines (150 loc) · 5.42 KB
/
install_kupiki_admin.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bash
check_returned_code() {
RETURNED_CODE=$@
if [ $RETURNED_CODE -ne 0 ]; then
display_message ""
display_message "Something went wrong with the last command. Please check the log file"
display_message ""
exit 1
fi
}
display_message() {
MESSAGE=$@
# Display on console
echo "::: $MESSAGE"
# Save it to log file
echo "::: $MESSAGE" >> $LOGPATH$LOGNAME
}
MY_IP=`ip -4 route get 8.8.8.8 | awk {'print $7'} | tr -d '\n'`
CLIENT_PROTOCOL=http
CLIENT_HOST=$MY_IP
CLIENT_PORT=8080
SERVER_PROTOCOL=http
SERVER_HOST=$MY_IP
SERVER_PORT=4000
FRONTEND_URL="https://github.com/Kupiki/Kupiki-Hotspot-Admin-Frontend.git"
BACKEND_URL="https://github.com/Kupiki/Kupiki-Hotspot-Admin-Backend.git"
BACKEND_SCRIPT_URL="https://github.com/Kupiki/Kupiki-Hotspot-Admin-Backend-Script.git"
display_message "Cloning Kupiki Admin Frontend"
cd $HOME
git clone $FRONTEND_URL
check_returned_code $?
display_message "Building Kupiki Admin Frontend image"
cd Kupiki-Hotspot-Admin-Frontend
docker build --build-arg CLIENT_HOST=$CLIENT_HOST --build-arg CLIENT_PORT=$CLIENT_PORT --build-arg SERVER_HOST=$SERVER_HOST --build-arg SERVER_PORT=$SERVER_PORT . -t admin-frontend
check_returned_code $?
display_message "Creating Kupiki Admin Frontend service"
cat > /etc/systemd/system/kupiki.admin.frontend.service << EOT
[Unit]
Description=Kupiki Administration Frontend
After=docker.service
Requires=docker.service
After=mariadb.service
Requires=mariadb.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=/usr/bin/docker stop -t 5 admin-frontend
ExecStart=/usr/bin/docker start -a admin-frontend
ExecStop=/usr/bin/docker stop -t 5 admin-frontend
[Install]
WantedBy=multi-user.target
EOT
display_message "Activating Kupiki Admin Frontend service"
chmod +x /etc/systemd/system/kupiki.admin.frontend.service
check_returned_code $?
/bin/systemctl enable /etc/systemd/system/kupiki.admin.frontend.service
check_returned_code $?
display_message "Starting Kupiki Admin Frontend container"
/usr/bin/docker run -d -p $CLIENT_PORT:80 --name=admin-frontend admin-frontend
check_returned_code $?
# display_message "Cleaning unwanted Docker images"
# docker rmi $(docker images --filter dangling=true -q) --force
# check_returned_code $?
display_message "Cloning Kupiki Admin Backend"
cd $HOME
git clone $BACKEND_URL
check_returned_code $?
display_message "Building Kupiki Admin Backend image"
cd Kupiki-Hotspot-Admin-Backend
docker build --build-arg CLIENT_HOST=$CLIENT_HOST --build-arg CLIENT_PORT=$CLIENT_PORT --build-arg SERVER_HOST=$SERVER_HOST --build-arg SERVER_PORT=$SERVER_PORT . -t admin-backend
check_returned_code $?
display_message "Creating Kupiki Admin Backend service"
cat > /etc/systemd/system/kupiki.admin.backend.service << EOT
[Unit]
Description=Kupiki Administration Backend
After=docker.service
Requires=docker.service
After=mariadb.service
Requires=mariadb.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=/usr/bin/docker stop -t 5 admin-backend
ExecStart=/usr/bin/docker start -a admin-backend
ExecStop=/usr/bin/docker stop -t 5 admin-backend
[Install]
WantedBy=multi-user.target
EOT
display_message "Activating Kupiki Admin Backend service"
chmod +x /etc/systemd/system/kupiki.admin.backend.service
check_returned_code $?
/bin/systemctl enable /etc/systemd/system/kupiki.admin.backend.service
check_returned_code $?
display_message "Starting Kupiki Admin Backend container"
/usr/bin/docker run -d -p $SERVER_PORT:$SERVER_PORT --network="host" --name=admin-backend admin-backend
check_returned_code $?
# display_message "Cleaning unwanted Docker images"
# docker rmi $(docker images --filter dangling=true -q) --force
# check_returned_code $?
display_message "Cloning Kupiki Admin Backend Script"
cd $HOME
git clone $BACKEND_SCRIPT_URL
check_returned_code $?
display_message "Creating Kupiki Admin rabbitmq service"
cat > /etc/systemd/system/kupiki.admin.rabbitmq.service << EOT
[Unit]
Description=Kupiki Administration RabbitMQ
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=/usr/bin/docker stop -t 5 rabbitmq
ExecStart=/usr/bin/docker start -a rabbitmq
ExecStop=/usr/bin/docker stop -t 5 rabbitmq
[Install]
WantedBy=multi-user.target
EOT
display_message "Activating Kupiki Admin rabbitmq service"
chmod +x /etc/systemd/system/kupiki.admin.rabbitmq.service
check_returned_code $?
/bin/systemctl enable /etc/systemd/system/kupiki.admin.rabbitmq.service
check_returned_code $?
display_message "Starting RabbitMQ"
/usr/bin/docker run -d -p 5672:5672 -p 15672:15672 --name=rabbitmq rabbitmq:management-alpine
check_returned_code $?
display_message "Copy of Kupiki Admin Script"
cp $HOME/Kupiki-Hotspot-Admin-Backend-Script/Script/kupikiListener.py /etc/kupiki/kupikiListener.py
check_returned_code $?
display_message "Creating Kupiki Admin Script service"
cat > /etc/systemd/system/kupiki.admin.script.service << EOT
[Unit]
Description=Kupiki Administration Script
After=kupiki.admin.rabbitmq.service
[Service]
Type=simple
Restart=always
RestartSec=20
ExecStart=/usr/bin/python /etc/kupiki/kupikiListener.py
[Install]
WantedBy=default.target
EOT
display_message "Activating Kupiki Admin script service"
chmod +x /etc/systemd/system/kupiki.admin.script.service
check_returned_code $?
/bin/systemctl enable /etc/systemd/system/kupiki.admin.script.service
check_returned_code $?
display_message "Waiting for RabbitMQ to be ready"
sleep 15
/bin/systemctl start kupiki.admin.script.service