-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserve
More file actions
executable file
·142 lines (120 loc) · 2.42 KB
/
serve
File metadata and controls
executable file
·142 lines (120 loc) · 2.42 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
# set -x
env_name=""
app_name="bern"
config_file=""
with_install="no"
with_reload="no"
text_banner="\
, __
/|/ \\
| __/ _ ,_ _ _
| \\|/ / | / |/ |
|(__/|__/ |_/ | |_/ by Lupine Software LLC
"
print_context() {
cat <<CTX
<context>
environment..... ${env_name}
config_file..... ${config_file}
install packages..... ${with_install}
with reload option..... ${with_reload}
CTX
}
print_usage() {
cat <<USG
Usage:
[ENV=] ${1} [options] <config_file>
Run server.
Options:
-c, --config load configuration from \`file\`
-e, --env set environment {development|production}
-h, --help display this help and exit
-i, --install install packages before run from pypi
-r, --reload run server with reload option
Positional arguments:
config_file config/{development|production}.ini (optional)
Examples:
% ENV=development serve --reload
% serve -e production -c config/production.ini
% serve --install -e production
USG
}
run_install_command() {
pip install -e ".[${1}]" -c constraints.txt
}
getopt --test > /dev/null
if [ $? -ne 4 ]; then
echo "\`getout --test\` failed"
fi
set -e
options=cehir
longoptions=config,env,help,install,reload
_=`getopt --name "${0}" \
--options "${options}" --longoptions "${longoptions}" --unquoted -- "${@}"`
if [ $? -ne 0 ]; then
exit 2
fi
while [ $# -gt 0 ]; do
case "${1}" in
-c|--config)
config_file="${2}"
shift
;;
-e|--env)
ENV="${2}"
shift
;;
-h|--help)
print_usage `basename $0`
exit 0
;;
-i|--install)
with_install="yes"
;;
-r|--reload)
with_reload="yes"
;;
*.ini)
ENV="${1/config\//}"
config_file="${1}"
;;
*)
echo "Unknown option :'("
exit 2
;;
esac
shift
done
if [ "${ENV}" = "" ]; then
ENV="development"
fi
if [ "${env_name}" = "" ]; then
env_name="${ENV}"
fi
case "${env_name}" in
"development"|"production")
echo -en "${text_banner}"
print_context
if [ "yes" = "${with_install}" ]; then
run_install_command $env_name
fi
if [ "production" = "${env_name}" ]; then
cmd="${app_name}_pstart"
else
cmd="${app_name}_pserve"
fi
if [ "yes" = "${with_reload}" ]; then
cmd="${cmd} --reload"
fi
echo
echo "<command>"
echo "% ${cmd} ${config_file}"
echo
$cmd $config_file
;;
*)
print_usage `basename $0`
exit 1
;;
esac