-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_server.sh
More file actions
57 lines (51 loc) · 994 Bytes
/
http_server.sh
File metadata and controls
57 lines (51 loc) · 994 Bytes
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
#!/bin/bash
SERVER="python3 -m http.server 3000"
PID=$(lsof -t -i:3000)
start_server() {
if [ -z "$PID" ]
then
echo "Starting server..."
$SERVER &>/dev/null &
echo "Server started on port 3000."
else
echo "Server is already running with PID: $PID"
fi
}
stop_server() {
if [ -z "$PID" ]
then
echo "Server is not running."
else
echo "Stopping server with PID: $PID..."
kill -9 $PID
echo "Server stopped."
fi
}
status_check() {
if [ -z "$PID" ]
then
echo "Server is not running."
else
echo "Server is running with PID: $PID"
fi
}
if [ $# -eq 0 ]
then
echo "No arguments provided. Please specify start, stop or status as an argument."
exit 1
fi
case "$1" in
start)
start_server
;;
stop)
stop_server
;;
status)
status_check
;;
*)
echo "Invalid option. Please specify start, stop or status as an argument."
exit 1
;;
esac