-
Notifications
You must be signed in to change notification settings - Fork 0
/
app
executable file
·151 lines (130 loc) · 3.59 KB
/
app
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
#!/bin/bash
needs_install () {
[ ! -x "$(command -v $1)" ]
}
if needs_install docker; then
echo "Please install docker";
exit;
fi
if [ ! -f '.env' ]; then
echo "Install default .env file - please check and amend if you want different ports"
cp .env.dist .env
fi
read_var() {
MY_VAR=$(grep $1 .env | xargs)
echo ${MY_VAR#*=}
}
exec () {
docker exec -td --user $(id -u) $CONTAINER_NAME $1 $2 $3 $4 $5 $6
}
exec_wo () {
docker exec -t $CONTAINER_NAME $1 $2 $3 $4 $5 $6
}
IMAGE=tanasecosminromeo/tensorflow-ws:latest
CONTAINER_NAME=tcr-tensorflow-ws
case "$1" in
'run'|'up')
mkdir -p -m 777 var/logs
mkdir -p -m 777 var/models
HTTP_PORT=$(read_var HTTP_PORT)
WEBSOCKET_PORT=$(read_var WEBSOCKET_PORT)
MAX_MEMORY=$(read_var MAX_MEMORY)
echo "Running $IMAGE as $CONTAINER_NAME exposing $HTTP_PORT as the HTTP port and $WEBSOCKET_PORT as the web socket port"
ALREADY_RUNNING=$(docker ps -aqf "name=tcr-tensorflow-ws")
if [ ! -z $ALREADY_RUNNING ]; then
docker start $CONTAINER_NAME
else
docker run -d --name $CONTAINER_NAME -v ${PWD}:/code --env-file ./.env -p $HTTP_PORT:8000 -p $WEBSOCKET_PORT:8001 -m $MAX_MEMORY -u $(id -u ${USER}):$(id -g ${USER}) $IMAGE
fi
exec pkill -f python3
exec python3 httpserver.py
exec python3 websocket.py
##Todo: Remove this. It should be run by the socket WHEN required
exec python3 src/detect ssd_mobilenet_v1_coco_11_06_2017
;;
'exec')
USER=$(whoami)
echo "Entering container as $USER"
docker exec -it $CONTAINER_NAME bash
;;
'sudo')
echo "Entering container as root"
docker exec -it --user root $CONTAINER_NAME bash
;;
'stop')
echo "Stopping $CONTAINER_NAME"
docker stop $CONTAINER_NAME
;;
'clear-logs')
rm -rf var/logs/*
;;
'logs')
echo "Logs of $CONTAINER_NAME"
docker logs $CONTAINER_NAME
;;
'restart')
echo "Restarting $CONTAINER_NAME"
./app stop
./app run
;;
'remove')
echo "Removing $CONTAINER_NAME"
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
;;
'build')
echo 'Building $IMAGE image'
docker build -t $IMAGE .
;;
'socket')
echo 'Refresh socket'
exec pkill -f websocket.py
exec python3 websocket.py
;;
'http')
echo 'Refresh http'
exec pkill -f httpserver.py
exec python3 httpserver.py
;;
'detections')
echo 'Refresh socket'
exec pkill -f detect.py
;;
'ps')
exec_wo ps au
;;
'kill')
if [ -z "$2" ]; then
echo "Which process do you want to kill?"
exec_wo ps au
read -p "Your command:" process
./app kill $process
exit;
fi
exec_wo pkill -f $2
;;
*)
echo -e '\n'
echo 'Container commands:'
echo -e '\t./app run\t\t - Starts the container'
echo -e '\t./app exec\t\t - Enter container'
echo -e '\t./app sudo\t\t - Enter container as root'
echo -e '\t./app stop\t\t - Stops the container'
echo -e '\t./app logs\t\t - Show all container logs'
echo -e '\t./app clear-logs\t - Clear logs'
echo -e '\t./app restart\t\t - Re-creates the container'
echo -e '\t./app remove\t\t - Removes the container'
echo -e '\t./app build\t\t - Build image'
echo -e '\n'
echo 'Application commands:'
echo -e '\t./app socket\t\t - Restarts the web socket server'
echo -e '\t./app http\t\t - Restarts the http server'
echo -e '\t./app detections\t - Kills any unset detect.py children'
echo 'Other commands:'
echo -e '\t./app ps\t\t - Shows all running processes'
echo -e '\t./app kill\t\t - Kill specific process'
echo -e '\n'
read -p "Your command:" command
./app $command
;;
esac