-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathnode-dockerfile-wrapper.sh
91 lines (80 loc) · 2.23 KB
/
node-dockerfile-wrapper.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
#!/bin/bash
EX_NUM=$1
EXEC_MODE=$2
ENV_SECRET="This is a secret"
if [[ -z "${EX_NUM// }" ]]; then
echo "Please set EX_NUM"
echo "Ex: EX_NUM=1 docker-compose up"
echo "Additional help: https://sts.tools/setup"
exit 1
fi
# Start the python server
python -m SimpleHTTPServer 8081 &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start python: $status"
exit $status
fi
# Start nodemon
npx "${EXEC_MODE:-nodemon}" "src/${EX_NUM}/${FILE:-app.js}"
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start Node: $status"
exit $status
fi
# The container will exit with an error if it detects that either
# of the processes has exited. Otherwise it will loop forever,
# waking up every 60 seconds
while /bin/true; do
ps aux | grep nodemon | grep -q -v grep
PROCESS_1_STATUS=$?
ps aux | grep python | grep -q -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they will exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit -1
fi
sleep 60
done
#!/bin/bash
EX_NUM=$1
EXEC_MODE=$2
ENV_SECRET="This is a secret"
if [[ -z "${EX_NUM// }" ]]; then
echo "Please set EX_NUM"
echo "Ex: EX_NUM=1 docker-compose up"
echo "Additional help: https://sts.tools/setup"
exit 1
fi
# Start the python server
python -m SimpleHTTPServer 8081 &
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start python: $status"
exit $status
fi
# Start nodemon
npx "${EXEC_MODE:-nodemon}" "src/${EX_NUM}/${FILE:-app.js}"
status=$?
if [ $status -ne 0 ]; then
echo "Failed to start Node: $status"
exit $status
fi
# The container will exit with an error if it detects that either
# of the processes has exited. Otherwise it will loop forever,
# waking up every 60 seconds
while /bin/true; do
ps aux | grep nodemon | grep -q -v grep
PROCESS_1_STATUS=$?
ps aux | grep python | grep -q -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they will exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit -1
fi
sleep 60
done