Skip to content

Commit 9f5a5f0

Browse files
committed
Re-Enable web server node cluster, and fix FD inheritance issue for listeners
1 parent 53382fb commit 9f5a5f0

File tree

5 files changed

+40
-20
lines changed

5 files changed

+40
-20
lines changed

src/deploy/NVA_build/noobaa_supervisor.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ autorestart=true
1717
stopsignal=KILL
1818
killasgroup=true
1919
stopasgroup=true
20+
autorestart=true
2021
directory=/root/node_modules/noobaa-core
2122
command=/usr/local/bin/node src/server/web_server.js
2223

src/deploy/NVA_build/supervisord.orig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ start() {
2121

2222
stop() {
2323
echo "Stopping ..."
24-
kill -9 `cat $PIDFILE`
24+
local p=$(cat $PIDFILE)
25+
kill -9 ${p}
26+
#unlink /tmp/supervisor.sock
27+
#local pid=$(lsof -i :8080|awk '{ print $2 }' | sed '1 d')
28+
#for p in ${pid} ; do
29+
#kill -9 ${p}
30+
#done
2531
[ $? -eq 0 ] && rm -f $PIDFILE
2632
return $retval
2733
}
@@ -35,6 +41,7 @@ case $1 in
3541
;;
3642
restart)
3743
stop
44+
sleep 1
3845
start
3946
;;
4047
*)

src/deploy/NVA_build/upgrade.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ VER_CHECK="/root/node_modules/noobaa-core/src/deploy/NVA_build/version_check.js"
1111
NEW_UPGRADE_SCRIPT="${EXTRACTION_PATH}noobaa-core/src/deploy/NVA_build/upgrade.sh"
1212

1313
function disable_supervisord {
14+
deploy_log "disable_supervisord"
1415
#services under supervisord
1516
local services=$($SUPERCTL status | grep pid | sed 's:.*pid \(.*\),.*:\1:')
1617
#disable the supervisord
@@ -22,9 +23,8 @@ function disable_supervisord {
2223
}
2324

2425
function enable_supervisord {
26+
deploy_log "enable_supervisord"
2527
${SUPERD}
26-
27-
2828
}
2929

3030
function restart_webserver {
@@ -114,18 +114,29 @@ function do_upgrade {
114114

115115
deploy_log "Running post upgrade"
116116
${WRAPPER_FILE_PATH}${WRAPPER_FILE_NAME} post
117+
deploy_log "Finished post upgrade"
117118

118119
enable_supervisord
120+
deploy_log "Enabling supervisor"
119121
#workaround - from some reason, without sleep + restart, the server starts with odd behavior
120122
#TODO: understand why and fix.
121123
sleep 5;
122124
restart_s3rver
125+
deploy_log "Restarted s3rver"
123126
restart_webserver
124127
deploy_log "Upgrade finished successfully!"
125128
}
126129

127130
deploy_log "upgrade.sh called with $@"
128131

132+
#Node.js Cluster chnages the .spawn behavour. On a normal spawn FDs are not inherited,
133+
#on a node cluster they are, which meand the listening ports of the webserver are inherited by this create_multipart_upload.
134+
#murder them
135+
fds=`lsof -p $$ | grep LISTEN | awk '{print $4}' | sed 's:\(.*\)u:\1:'`
136+
for f in ${fds}; do
137+
exec ${f}<&-
138+
done
139+
129140
if [ "$1" == "from_file" ]; then
130141
if [ "$2" != "" ]; then
131142
cp -f $2 ${TMP_PATH}${PACKAGE_FILE_NAME}

src/deploy/NVA_build/upgrade_wrapper.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function post_upgrade {
156156

157157
#Installation ID generation if needed
158158
#TODO: Move this into the mongo_upgrade.js
159-
local id=$(/mongodb/bin/mongo nbcore --eval "db.clusters.find().shellPrint()" | grep cluster_id | wc -l)
159+
local id=$(/usr/bin/mongo nbcore --eval "db.clusters.find().shellPrint()" | grep cluster_id | wc -l)
160160
if [ ${id} -eq 0 ]; then
161161
id=$(uuidgen)
162162
/usr/bin/mongo nbcore --eval "db.clusters.insert({cluster_id: '${id}'})"
@@ -191,7 +191,6 @@ function post_upgrade {
191191
deploy_log "list core dir"
192192
deploy_log "$(ls -R ${CORE_DIR}/build/)"
193193

194-
/etc/rc.d/init.d/supervisord restart
195194
sudo grep noobaa /etc/sudoers
196195
if [ $? -ne 0 ]; then
197196
deploy_log "adding noobaa to sudoers"
@@ -203,8 +202,10 @@ function post_upgrade {
203202

204203
fi
205204

206-
207-
rm -f /tmp/*.tar.gz
205+
rm -f /tmp/*.tar.gz
206+
207+
/etc/rc.d/init.d/supervisord stop
208+
/etc/rc.d/init.d/supervisord start
208209
}
209210

210211

src/server/web_server.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ dotenv.load();
4343

4444

4545
// Temporary removed - causes issues with upgrade.
46-
//var numCPUs = Math.ceil(require('os').cpus().length / 2);
47-
// if (cluster.isMaster) {
48-
// // Fork MD Servers
49-
// for (var i = 0; i < numCPUs; i++) {
50-
// console.warn('Spawning MD Server', i + 1);
51-
// cluster.fork();
52-
// }
53-
//
54-
// cluster.on('exit', function(worker, code, signal) {
55-
// console.log('MD Server ' + worker.process.pid + ' died');
56-
// });
57-
// return;
58-
// }
46+
var numCPUs = Math.ceil(require('os').cpus().length / 2);
47+
if (cluster.isMaster) {
48+
// Fork MD Servers
49+
for (var i = 0; i < numCPUs; i++) {
50+
console.warn('Spawning MD Server', i + 1);
51+
cluster.fork();
52+
}
53+
54+
cluster.on('exit', function(worker, code, signal) {
55+
console.log('MD Server ' + worker.process.pid + ' died');
56+
});
57+
return;
58+
}
5959

6060
dbg.set_process_name('WebServer');
6161

0 commit comments

Comments
 (0)