-
Notifications
You must be signed in to change notification settings - Fork 16
/
flask.sh
95 lines (87 loc) · 2.67 KB
/
flask.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
#!/bin/sh
export FLASK_PATH=/app/flask/tlv8-python-flask
export FLASK_PID=$FLASK_PATH/flask.pid
#export FLASK_PROJECT=$FLASK_PATH/tlv8-python-flask
echo $FLASK_PATH
if [ "$1" = "start" ]; then
if [ ! -z "$FLASK_PID" ]; then
if [ -f "$FLASK_PID" ]; then
if [ -s "$FLASK_PID" ]; then
echo "Existing PID file found during start."
if [ -r "$FLASK_PID" ]; then
PID=$(cat "$FLASK_PID")
ps -p $PID >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Flask appears to still be running with PID $PID. Start aborted."
echo "If the following process is not a Flask process, remove the PID file and try again:"
ps -f -p $PID
exit 1
else
echo "Removing/clearing stale PID file."
rm -f "$FLASK_PID" >/dev/null 2>&1
if [ $? != 0 ]; then
if [ -w "$FLASK_PID" ]; then
cat /dev/null >"$FLASK_PID"
else
echo "Unable to remove or clear stale PID file. Start aborted."
exit 1
fi
fi
fi
else
echo "Unable to read PID file. Start aborted."
exit 1
fi
else
rm -f "$FLASK_PID" >/dev/null 2>&1
if [ $? != 0 ]; then
if [ ! -w "$FLASK_PID" ]; then
echo "Unable to remove or write to empty PID file. Start aborted."
exit 1
fi
fi
fi
fi
fi
echo "To Start Flask"
if [ -z "$FLASK_PROJECT" ]; then
echo "Message: \$FLASK_PROJECT not set"
else
cd $FLASK_PROJECT
pwd
fi
source venv/bin/activate
echo "Load flask venv"
mkdir -p $FLASK_PATH/logs >/dev/null 2>&1
echo "Log folder created"
nohup python server.py >$FLASK_PATH/logs/flask.log 2>&1 &
echo "start in nohup"
echo $! >$FLASK_PID
echo "PID:$(cat $FLASK_PID)"
echo "Flask started."
elif [ "$1" = "stop" ]; then
if [ ! -z "$FLASK_PID" ]; then
if [ -f "$FLASK_PID" ]; then
if [ -s "$FLASK_PID" ]; then
kill -0 $(cat "$FLASK_PID") >/dev/null 2>&1
if [ $? -gt 0 ]; then
echo "PID file found but either no matching process was found or the current user does not have permission to stop the process. Stop aborted."
exit 1
fi
else
echo "PID file is empty and has been ignored."
fi
else
echo "\$FLASK_PID was set but the specified file does not exist. Is Flask running? Stop aborted."
exit 1
fi
fi
echo "To Stop Flask"
kill -9 $(cat $FLASK_PID) >/dev/null 2>&1
echo "Flask stopped."
rm -f $FLASK_PID >/dev/null 2>&1
echo "PID File cleared."
else
echo "Action Type No Support."
exit 1
fi