-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote-start.sh
54 lines (43 loc) · 1.55 KB
/
remote-start.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
#!/bin/bash
# Set Oracle environment
if [ -d /opt/oracle/instantclient_19_8 ]; then
export ORACLE_HOME=/opt/oracle/instantclient_19_8
export LD_LIBRARY_PATH=$ORACLE_HOME
elif [ -d /usr/lib/oracle/19.6/client64/lib ]; then
export ORACLE_HOME=/usr/lib/oracle/19.6/client64
# 19.* libraries will be already configured by ldconfig
#export LD_LIBRARY_PATH=$ORACLE_HOME/lib
elif [ -d /usr/lib/oracle/12.2/client64/lib ]; then
export ORACLE_HOME=/usr/lib/oracle/12.2/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
else
echo "Oracle not found..."
exit 1
fi
# Configure the shared Node library on the undergrad server.
export NODE_PATH=/cs/local/generic/lib/cs304/node_modules
# File path
ENV_SERVER_PATH="./.env"
# Check the database host name and port
sed -i "/^ORACLE_HOST=/c\ORACLE_HOST=dbhost.students.cs.ubc.ca" $ENV_SERVER_PATH
sed -i "/^ORACLE_PORT=/c\ORACLE_PORT=1522" $ENV_SERVER_PATH
# Define a range
START=50000
END=60000
# Loop through the range and check if the port is in use
for PORT in $(seq $START $END); do
# Use lsof to check if the port is in use
if ! lsof -i :$PORT > /dev/null; then
# Bind to the port using a temporary process
nc -l -p $PORT &
TEMP_PID=$!
# Update the port number in the .env file
sed -i "/^PORT=/c\PORT=$PORT" $ENV_SERVER_PATH
echo "Updated $ENV_SERVER_PATH with PORT=$PORT."
# Kill the temporary process
kill $TEMP_PID
# Replace the bash process with the Node process
exec node server.js
break
fi
done