-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·157 lines (147 loc) · 5.59 KB
/
run.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
#!/bin/bash
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
python_noterm_bare() {
echo -e "$GREEN[+] Launching python script in background$NC"
./noterm_wait.py &
child_pid=$!
echo -e "$GREEN[+] PID of python script: $child_pid$NC"
echo -e "$GREEN[+] Sending SIGTERM to PID $child_pid$NC"
kill -s TERM $child_pid
if ps -p $child_pid > /dev/null
then
echo -e "$RED[!] PID $child_pid is still running$NC"
else
echo -e "$GREEN[+] PID $child_pid is not running$NC"
fi
}
python_term_bare() {
echo -e "$GREEN[+] Launching python script in background$NC"
./term_wait.py > ./term_wait.log &
sleep 1
child_pid=$!
echo -e "$GREEN[+] PID of python script: $child_pid$NC"
echo -e "$GREEN[+] Sending SIGTERM to PID $child_pid$NC"
kill -s TERM $child_pid
sleep 1
if ps -p $child_pid > /dev/null
then
echo -e "$RED[!] PID $child_pid is still running$NC"
else
echo -e "$GREEN[+] PID $child_pid is not running$NC"
fi
echo -e "$GREEN[+] PID $child_pid process stdout:$NC"
echo ""
cat ./term_wait.log
rm ./term_wait.log
}
python_noterm_docker_noinit() {
echo -e "$GREEN[+] Launching python script in Docker container$NC"
docker run -d -v $PWD/noterm_wait.py:/noterm_wait.py --rm --name python_noinit python:3.11.1-alpine python3 /noterm_wait.py
sleep 1
echo -e "$GREEN[+] ps command output in container:$NC"
echo ""
docker exec -it python_noinit ps -ef
echo -e "$GREEN[+] Stopping docker container and timing it. If it takes more then 10 seconds, it means"
echo -e " that docker killing the process.$NC"
time docker stop python_noinit
}
python_term_docker_noinit() {
echo -e "$GREEN[+] Launching python script in Docker container$NC"
docker run -d -v $PWD/term_wait.py:/term_wait.py --name python_noinit python:3.11.1-alpine python3 /term_wait.py
sleep 1
echo -e "$GREEN[+] ps command output in container:$NC"
echo ""
docker exec -it python_noinit ps -ef
echo -e "$GREEN[+] Stopping docker container and timing it. If it takes more then 10 seconds, it means"
echo -e " that docker killing the process.$NC"
time docker stop python_noinit > /dev/null
echo -e "$GREEN[+] Container logs:$NC"
echo ""
docker logs python_noinit
docker rm python_noinit > /dev/null
}
python_noterm_docker_init() {
echo -e "$GREEN[+] Launching python script in Docker container with init as PID 1$NC"
docker run -d -v $PWD/noterm_wait.py:/noterm_wait.py --rm --init --name python_init python:3.11.1-alpine python3 /noterm_wait.py
sleep 1
echo -e "$GREEN[+] ps command output in container:$NC"
echo ""
docker exec -it python_init ps -ef
echo -e "$GREEN[+] Stopping docker container and timing it. If it takes more then 10 seconds, it means"
echo -e " that docker killing the process.$NC"
time docker stop python_init
}
python_term_docker_init() {
echo -e "$GREEN[+] Launching python script in Docker container$NC"
docker run -d -v $PWD/term_wait.py:/term_wait.py --init --name python_init python:3.11.1-alpine python3 /term_wait.py
sleep 1
echo -e "$GREEN[+] ps command output in container:$NC"
echo ""
docker exec -it python_init ps -ef
echo -e "$GREEN[+] Stopping docker container and timing it. If it takes more then 10 seconds, it means"
echo -e " that docker killing the process.$NC"
time docker stop python_init > /dev/null
echo -e "$GREEN[+] Container logs:$NC"
echo ""
docker logs python_init
docker rm python_init > /dev/null
}
multi_python_docker_noinit() {
echo -e "$GREEN[+] Launching multiple python scripts in Docker container$NC"
docker run -d -v $PWD:/app --name multi_python_noinit python:3.11.1-bullseye bash /app/entrypoint.sh
sleep 1
echo -e "$GREEN[+] ps command output in container:$NC"
echo ""
docker exec -it multi_python_noinit ps -ef
echo -e "$GREEN[+] Stopping docker container and timing it. If it takes more then 10 seconds, it means"
echo -e " that docker killing the process.$NC"
time docker stop multi_python_noinit > /dev/null
echo -e "$GREEN[+] Container logs:$NC"
echo ""
docker logs multi_python_noinit
docker rm multi_python_noinit > /dev/null
}
multi_python_docker_init() {
echo -e "$GREEN[+] Launching multiple python scripts in Docker container with init$NC"
cat ./python_tini.dockerfile | docker build -t python_with_tini -
docker run -d -v $PWD:/app --name multi_python_init python_with_tini bash /app/multi_python_entrypoint.sh
sleep 1
echo -e "$GREEN[+] ps command output in container:$NC"
echo ""
docker exec -it multi_python_init ps -ef
echo -e "$GREEN[+] Stopping docker container and timing it. If it takes more then 10 seconds, it means"
echo -e " that docker killing the process.$NC"
time docker stop multi_python_init > /dev/null
echo -e "$GREEN[+] Container logs:$NC"
echo ""
docker logs multi_python_init
docker rm multi_python_init > /dev/null
}
case $1 in
"python_noterm_bare" )
python_noterm_bare;
;;
"python_term_bare" )
python_term_bare;
;;
"python_noterm_docker_noinit" )
python_noterm_docker_noinit;
;;
"python_term_docker_noinit" )
python_term_docker_noinit;
;;
"python_noterm_docker_init" )
python_noterm_docker_init;
;;
"python_term_docker_init" )
python_term_docker_init;
;;
"multi_python_docker_noinit" )
multi_python_docker_noinit;
;;
"multi_python_docker_init" )
multi_python_docker_init;
;;
esac