Skip to content

Commit 5dc485c

Browse files
committed
Optimize Passenger installation
1 parent e0addef commit 5dc485c

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

scripts/install.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,13 @@ git clone https://github.com/TIOJ-INFOR-Online-Judge/tioj-judge.git
109109

110110
# Install gems
111111
cd "$WORKDIR/tioj"
112+
gem install passenger:'~> 6' -N
113+
PASSENGER_LOG=$(sudo mktemp -d)
114+
sudo chmod 755 $PASSENGER_LOG
115+
export rvmsudo_secure_path=1
116+
rvmsudo -b bash -c "passenger-install-nginx-module --force-colors --auto --auto-download --languages ruby > $PASSENGER_LOG/log 2>&1; touch $PASSENGER_LOG/finished"
112117
MAKEFLAGS='-j4' bundle install
113118

114-
# Setup nginx
115-
rvmsudo_secure_path=1 rvmsudo passenger-install-nginx-module --auto --auto-download --languages ruby
116-
sudo sed -i "s/^.*nobody.*$/user $USER;/" /opt/nginx/conf/nginx.conf
117-
sudo sed -i 's/http {/\0\n passenger_app_env production;/' /opt/nginx/conf/nginx.conf
118-
sudo sed -i "s|^[^#]*server_name.*localhost.*$|\0\n passenger_enabled on;\n root $(pwd)/public;|" /opt/nginx/conf/nginx.conf
119-
sudo sed -Ei "/^ *location \//, /\}/ s|^ {8}|\0# |" /opt/nginx/conf/nginx.conf
120-
121119
# Setup database
122120
cat <<EOF > config/database.yml
123121
default: &default
@@ -166,7 +164,7 @@ cd "$WORKDIR/tioj-judge"
166164
mkdir -p build
167165
cd build
168166
cmake -G Ninja ..
169-
ninja
167+
ninja -j $(($(nproc)-2))
170168
sudo ninja install
171169

172170
sudo tee /etc/tioj-judge.conf <<EOF > /dev/null
@@ -176,6 +174,20 @@ parallel = 2
176174
max_submission_queue_size = 20
177175
EOF
178176

177+
# Setup nginx
178+
cd "$WORKDIR/tioj"
179+
tail -f -n +1 $PASSENGER_LOG/log &
180+
TAIL_PID=$!
181+
until stat $PASSENGER_LOG/finished > /dev/null 2>&1; do
182+
sleep 1
183+
done
184+
kill $TAIL_PID
185+
sudo rm -rf $PASSENGER_LOG
186+
sudo sed -i "s/^.*nobody.*$/user $USER;/" /opt/nginx/conf/nginx.conf
187+
sudo sed -i 's/http {/\0\n passenger_app_env production;/' /opt/nginx/conf/nginx.conf
188+
sudo sed -i "s|^[^#]*server_name.*localhost.*$|\0\n passenger_enabled on;\n root $(pwd)/public;|" /opt/nginx/conf/nginx.conf
189+
sudo sed -Ei "/^ *location \//, /\}/ s|^ {8}|\0# |" /opt/nginx/conf/nginx.conf
190+
179191
# Setup systemctl
180192
cat <<EOF | sudo tee /etc/systemd/system/nginx.service > /dev/null
181193
[Unit]

0 commit comments

Comments
 (0)