forked from neurdb/neurdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-init.sh
More file actions
138 lines (113 loc) · 3.6 KB
/
docker-init.sh
File metadata and controls
138 lines (113 loc) · 3.6 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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Print each command before executing it
set -x
# Variables (can be changed by user)
NEURDBPATH=${NEURDBPATH:-/code/neurdb-dev}
NR_PSQL_PATH=${NR_PSQL_PATH:-$NEURDBPATH/psql}
NR_DBDATA_PATH=${NR_DBDATA_PATH:-$NR_PSQL_PATH/data}
# Variables (cannot be changed by user)
NR_DBENGINE_PATH=$NEURDBPATH/dbengine
NR_AIENGINE_PATH=$NEURDBPATH/aiengine
NR_API_PATH=$NEURDBPATH/api
#NR_PIPELINE_PATH=$NR_DBENGINE_PATH/nr_kernel/nrext
NR_KERNEL_PATH=$NR_DBENGINE_PATH/nr_kernel
# Clean log file
rm $NEURDBPATH/logfile || true
# Clean the psql folder (only for debugging purposes)
# rm -rf $NR_PSQL_PATH || true
# # Install external lib.
# git clone https://github.com/facebook/rocksdb.git
# cd rocksdb
# make shared_lib -j
# sudo make install-shared
# Create psql folder
mkdir -p $NR_PSQL_PATH
# Compile PostgreSQL
cd $NR_DBENGINE_PATH
make distclean || true
./configure --prefix=$NR_PSQL_PATH --enable-debug
make -j
make install
echo 'Done! Now start the database'
# Crete DB engine if not exist
if [ ! -d "$NR_DBDATA_PATH" ]; then
mkdir -p $NR_DBDATA_PATH
$NR_PSQL_PATH/bin/initdb -D $NR_DBDATA_PATH
else
# make sure DBDATA folder is under permission 0750 to avoid PG start failure
sudo chmod 0750 $NR_DBDATA_PATH
fi
# Start DB engine
$NR_PSQL_PATH/bin/pg_ctl -D $NR_DBDATA_PATH -l logfile start
# Wait a few seconds to ensure DB engine is up and running
until $NR_PSQL_PATH/bin/psql -h localhost -p 5432 -U neurdb -c '\q'; do
>&2 echo 'NeurDB is unavailable - sleeping'
sleep 1
# try to create `neurdb` database into the cluster
$NR_PSQL_PATH/bin/createdb -h localhost -p 5432 neurdb
done
echo "DB Started!"
# Load iris dataset
# $NR_PSQL_PATH/bin/psql -h localhost -p 5432 -U neurdb -f $NEURDBPATH/dataset/iris/iris_psql.sql
# Install neurdb package
cd $NR_API_PATH/python
## For older setuptools
## Reference: https://stackoverflow.com/a/71946741
touch setup.cfg
sudo pip install -e .
rm setup.cfg
## For newer setuptools
# pip install -e . --config-settings editable_mode=compat
# Install socket.io-client-cpp (for nr_pipeline)
## Since we have migrated to websockets, we don't need this
# if [ ! -d "$NR_PIPELINE_PATH/lib" ]; then
# mkdir -p $NR_PIPELINE_PATH/lib
# fi
# cd $NR_PIPELINE_PATH/lib
# if [ ! -d "socket.io-client-cpp" ]; then
# git clone --recurse-submodules https://github.com/socketio/socket.io-client-cpp.git
# fi
# cd socket.io-client-cpp
# sudo chmod -R 777 ./
# cmake -DCMAKE_CXX_FLAGS="-fPIC" ./
# sudo make -j
# sudo make install
# Compile nr_pipeline
#cd $NR_PIPELINE_PATH
#sudo make clean
#sudo make install
#echo "Install NR Data Pipeline Extension & NR kernel extension Done"
# Compile nr_kernel
cd $NR_KERNEL_PATH
sudo make clean
sudo make install
## Register nr_kernel as preloaded library
echo 'shared_preload_libraries = '\''nr_ext, nram, pg_neurstore'\''' >> $NR_DBDATA_PATH/postgresql.conf
echo "Install NR Data Pipeline Extension & NR kernel extension Done"
# Run python server
cd $NR_AIENGINE_PATH/runtime
export NR_LOG_LEVEL=INFO # Set log level
nohup python server.py &
echo 'Python Server started!'
echo "Please use 'control + c' to exit the logging print"
if [ "$GITHUB_ACTIONS" != "true" ]; then
# If not in GitHub Actions, keep container running
tail -f /dev/null
else
# If in GitHub Actions
# Wait for Python server to start
echo -n 'Waiting for Python server to start '
until curl --output /dev/null --silent --head --fail http://127.0.0.1:8090/; do
printf '.'
sleep 1
done
echo 'OK'
# Do test
cd $NEURDBPATH/test
export PATH=$NR_PSQL_PATH/bin:$PATH
bash test.sh
# Exit normally
exit 0
fi