-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfastapi_service.sh
More file actions
executable file
·56 lines (50 loc) · 1.05 KB
/
fastapi_service.sh
File metadata and controls
executable file
·56 lines (50 loc) · 1.05 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
#!/bin/bash
APP="uvicorn main:app --host 192.168.1.48 --port 8001"
PID_FILE="fastapi_service.pid"
start() {
if [ -f $PID_FILE ]; then
echo "Service is already running. Stop it first."
else
echo "Starting FastAPI service..."
nohup $APP > fastapi_service.log 2>&1 & echo $! > $PID_FILE
echo "Service started with PID $(cat $PID_FILE)"
fi
}
stop() {
if [ -f $PID_FILE ]; then
echo "Stopping FastAPI service..."
kill $(cat $PID_FILE) && rm -f $PID_FILE
echo "Service stopped."
else
echo "Service is not running."
fi
}
restart() {
echo "Restarting FastAPI service..."
stop
start
}
status() {
if [ -f $PID_FILE ]; then
echo "Service is running with PID $(cat $PID_FILE)"
else
echo "Service is not running."
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac