-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_server_manager
executable file
·70 lines (56 loc) · 2.08 KB
/
_server_manager
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
#! /bin/bash
clear
### Import env vars from .env
source .env
# If no argument provided to script, then prompt user to select an option
option=$1
if [[ -z $option ]]; then
echo """
======================================================================
CHOOSE ONE OF THESE OPTIONS FOR RUNNING EXPRESS SERVER:
(N.b. These options can be passed to script as argument)
1. Run in development mode (with auto-recompilation)
2. Build a production version (output to ./dist-server)
3. Run a production version (at ./dist-server)
4. Daemonize production server (at ./dist-server)
======================================================================
"""
read choice
option=$choice
fi
# Test if chosen option is a number between 1 and 5
if [[ ! $option =~ ^[0-9]+$ || ! $option -ge 1 || ! $option -le 5 ]]; then
echo "Chosen option ("$option") was NOT a number between 1 and 4"
exit 1
fi
# Execute code based on chosen option
if [[ $option -eq 1 ]]; then
echo ">>> Starting server in development mode on port "$SERVER_PORT
sleep 1
rm -rf dist-server
./node_modules/.bin/tsc-watch --skipLibCheck -p src/server/tsconfig.json --onSuccess "node dist-server/server/index.js"
fi
if [[ $option -eq 2 || $option -eq 3 ]]; then
echo ">>> Building local production server"
rm -rf dist-server
./node_modules/.bin/tsc --skipLibCheck -p src/server/tsconfig.json
fi
if [[ $option -eq 3 ]]; then
echo ">>> Running local production server"
node ./dist-server/server/index.js
fi
if [[ $option -eq 4 ]]; then
if [[ ! $(command -v pm2) ]]; then
echo ">>> NOTE: You don't have pm2 globablly installed."
echo ">>> Either install it globally or run from here: ./node_modules/.bin/pm2"
pm2=./node_modules/.bin/pm2
sleep 2
fi
echo ">>> Daemonizing local production server with pm2"
echo ">>> Run \`pm2 stop $PM2_LABEL\` to stop job"
echo ">>> Run \`pm2 delete $PM2_LABEL\` to delete job"
echo ">>> Run \`pm2 log $PM2_LABEL\` for logs"
echo ">>> Run \`pm2 monit $PM2_LABEL\` for monitoring"
echo ""
pm2 start dist-server/server/index.js -n $PM2_LABEL
fi