This repository was archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathserver.sh
More file actions
executable file
·76 lines (64 loc) · 1.28 KB
/
server.sh
File metadata and controls
executable file
·76 lines (64 loc) · 1.28 KB
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
#! /bin/sh
cd "${0%/*}"
PORT=9000
pid_file=".pid"
open_port_pid() {
lsof -ti :$PORT
}
is_running() {
[ ! -z "$(open_port_pid)" ]
}
case "$1" in
start)
if is_running; then
echo '\n-> Server is already running. Try stopping it first'
exit 0
fi
echo '\n-> Starting echoserver'
LOGS=/tmp/wstest.log
python3 echoserver.py $PORT > $LOGS 2>&1 &
echo "$!" > $pid_file
sleep .5
if ! is_running; then
echo 1
cat $LOGS
fi
echo "Logs can be found at $LOGS"
;;
stop)
if [ ! -f $pid_file ]; then
echo '\n-> PID not found. Attempting stop anyway'
PID=$(open_port_pid)
else
PID=$(cat $pid_file)
fi
if ! is_running; then
echo '\n-> Server not running'
exit 1
fi
echo "\n-> Stopping echoserver [$PID]"
kill -9 $PID
rm $pid_file > /dev/null
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0