-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_server.sh
executable file
·47 lines (38 loc) · 1.07 KB
/
start_server.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
#!/usr/bin/env bash
ARGS=$*
function main() {
set -e # Exit if any command fails
cd $(dirname $0)
if [[ ${ARGS} == *--prod* ]]; then
start_prod_server
else
start_dev_server
fi
}
function command_exists() {
command -v "$1" >/dev/null
}
function start_prod_server() {
if ! command_exists sudo && ! cygwin_run_as_administrator; then
echo "Cygwin must be run as administrator"
exit 1
fi
./build.sh
if command_exists sudo; then
echo -e "\nUsing system port requires sudo privileges"
sudo NODE_ENV=production node dist/server
else
NODE_ENV=production node dist/server
fi
}
function cygwin_run_as_administrator() {
id --groups | grep --quiet --extended-regexp '\<(114|544)\>'
}
function start_dev_server() {
mkdir --parent logs
touch logs/server.log logs/error.log
npx nodemon > >(tee -a logs/server.log) 2> >(tee -a logs/error.log >&2) &
trap "kill $!" EXIT SIGINT SIGKILL # Kill all child process if this process is stopped/ends
npx ng serve --open --ssl > >(tee -a logs/server.log) 2> >(tee -a logs/error.log >&2)
}
main