@@ -5,11 +5,13 @@ HOST="${NEST_SERVER_HOST:-127.0.0.1}"
5
5
LOGFILE=" ${NEST_SERVER_LOGFILE:-/ tmp/ nest-server.log} "
6
6
PORT=" ${NEST_SERVER_PORT:- 52425} "
7
7
STDOUT=" ${NEST_SERVER_STDOUT:- 0} "
8
+ TIMEOUT=" ${NEST_SERVER_TIMEOUT:- 30} "
9
+ WORKERS=" ${NEST_SERVER_WORKERS:- 1} "
8
10
9
11
usage () {
10
12
echo " NEST Server"
11
13
echo " -----------"
12
- echo " Usage: nest-server log|status|start|stop|restart [-d] [-h <HOST>] [-o] [-p <PORT>]"
14
+ echo " Usage: nest-server log|status|start|stop|restart [-d] [-h <HOST>] [-o] [-p <PORT>] [-t <TIMEOUT>] [-w <WORKERS>] "
13
15
echo " "
14
16
echo " Commands:"
15
17
echo " log display the server output log"
@@ -23,6 +25,8 @@ usage() {
23
25
echo " -h <HOST> use hostname/IP address <HOST> for the server [default: 127.0.0.1]"
24
26
echo " -o print NEST outputs to the console"
25
27
echo " -p <PORT> use port <PORT> for opening the socket [default: 52425]"
28
+ echo " -t <TIMEOUT> workers silent for more than this many seconds are killed and restarted [default: 30]"
29
+ echo " -w <WORKERS> the number of worker processes for handling requests [default: 1]"
26
30
}
27
31
28
32
log () {
@@ -38,13 +42,11 @@ pid() {
38
42
set-gunicorn_opts () {
39
43
# Set opts for gunicorn.
40
44
GUNICORN_OPTS=" --bind ${HOST} :${PORT} "
41
- if [ " ${DAEMON} " -eq 1 ]; then
42
- GUNICORN_OPTS=" ${GUNICORN_OPTS} --daemon"
43
- fi
44
- if [ " ${STDOUT} " -eq 0 ]; then
45
- GUNICORN_OPTS=" ${GUNICORN_OPTS} --capture-output"
46
- fi
47
45
GUNICORN_OPTS=" ${GUNICORN_OPTS} --log-file ${LOGFILE} "
46
+ [[ " ${DAEMON} " -eq 1 ]] && GUNICORN_OPTS=" ${GUNICORN_OPTS} --daemon"
47
+ [[ " ${STDOUT} " -eq 0 ]] && GUNICORN_OPTS=" ${GUNICORN_OPTS} --capture-output"
48
+ [[ " ${TIMEOUT} " -ne 30 ]] && GUNICORN_OPTS=" ${GUNICORN_OPTS} --timeout ${TIMEOUT} "
49
+ [[ " ${WORKERS} " -gt 1 ]] && GUNICORN_OPTS=" ${GUNICORN_OPTS} --workers ${WORKERS} "
48
50
}
49
51
50
52
start () {
@@ -55,21 +57,21 @@ start() {
55
57
echo " NEST Server is now running at http://${HOST} :${PORT} ."
56
58
if [ " ${DAEMON} " -eq 0 ]; then
57
59
echo " Use CTRL + C to stop this service."
58
- if [ " ${STDOUT} " -eq 1 ]; then
59
- echo " -----------------------------------------------------"
60
- fi
60
+ [[ " ${STDOUT} " -eq 1 ]] && echo " -----------------------------------------------------"
61
61
fi
62
62
63
63
set-gunicorn_opts
64
+ # shellcheck disable=SC2086
64
65
exec gunicorn nest.server:app ${GUNICORN_OPTS}
65
66
fi
66
67
}
67
68
68
69
status () {
69
70
# List all processes of NEST Server.
70
- PS_AUX=" $( ps aux | grep " [g]unicorn nest.server.app" ) "
71
- printf " USER\t\t\tPID\t\tHTTP-SOCKET\n"
72
- echo " ${PS_AUX} " | head -n 1 | awk ' { for(i=1;i<=NF;i++) {if ( i == 1 || i == 2 || i == 15 ) printf $i"\t\t"}; printf "\n" }'
71
+ PS_AUX=" $( pgrep -af " gunicorn nest.server.app" ) "
72
+ printf " PID\t\tHTTP-SOCKET\t\tLOGFILE\n"
73
+ echo " ${PS_AUX} " | head -n 1 | awk \
74
+ ' { for(i=1;i<=NF;i++) {if ( i == 1 || i == 6 || i == 8 ) printf $i"\t\t"}; printf "\n" }'
73
75
}
74
76
75
77
stop () {
@@ -84,12 +86,15 @@ stop() {
84
86
}
85
87
86
88
CMD=$1 ; shift
87
- while getopts " dh:op:" opt; do
89
+ while getopts " dh:op:t:w: " opt; do
88
90
case $opt in
89
91
d) DAEMON=1 ;;
90
92
h) HOST=$OPTARG ;;
91
93
o) STDOUT=1 ;;
92
94
p) PORT=$OPTARG ;;
95
+ t) TIMEOUT=$OPTARG ;;
96
+ w) WORKERS=$OPTARG ;;
97
+ * ) echo " Invalid option"
93
98
esac
94
99
done
95
100
0 commit comments