Improve containers stopping performance by handling SIGTERM
This commit is contained in:
parent
b9adb6f854
commit
fef00b96f1
|
@ -35,7 +35,10 @@ expressWs(app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fss.chmodSync(path.join(config.data_directory, globals.data_directories.jobs), 0o711)
|
fss.chmodSync(
|
||||||
|
path.join(config.data_directory, globals.data_directories.jobs),
|
||||||
|
0o711
|
||||||
|
);
|
||||||
|
|
||||||
logger.info('Loading packages');
|
logger.info('Loading packages');
|
||||||
const pkgdir = path.join(
|
const pkgdir = path.join(
|
||||||
|
@ -92,7 +95,12 @@ expressWs(app);
|
||||||
logger.debug('Calling app.listen');
|
logger.debug('Calling app.listen');
|
||||||
const [address, port] = config.bind_address.split(':');
|
const [address, port] = config.bind_address.split(':');
|
||||||
|
|
||||||
app.listen(port, address, () => {
|
const server = app.listen(port, address, () => {
|
||||||
logger.info('API server started on', config.bind_address);
|
logger.info('API server started on', config.bind_address);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
process.on('SIGTERM', () => {
|
||||||
|
server.close();
|
||||||
|
process.exit(0)
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y unzip autoconf build-essential libssl-d
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
|
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
|
||||||
|
|
||||||
ADD entrypoint.sh mkindex.sh /
|
ADD entrypoint.sh mkindex.sh serve.py /
|
||||||
|
|
||||||
ENTRYPOINT ["bash","/entrypoint.sh"]
|
ENTRYPOINT ["bash","/entrypoint.sh"]
|
||||||
CMD ["--no-build"]
|
CMD ["--no-build"]
|
||||||
|
|
|
@ -27,7 +27,7 @@ do
|
||||||
echo "Done with package $pkg"
|
echo "Done with package $pkg"
|
||||||
elif [[ $CI -eq 1 ]]; then
|
elif [[ $CI -eq 1 ]]; then
|
||||||
echo "Commit SHA: $pkg"
|
echo "Commit SHA: $pkg"
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
echo "Changed files:"
|
echo "Changed files:"
|
||||||
git diff --name-only $pkg^1 $pkg
|
git diff --name-only $pkg^1 $pkg
|
||||||
|
@ -52,8 +52,8 @@ echo "Index created"
|
||||||
|
|
||||||
if [[ $SERVER -eq 1 ]]; then
|
if [[ $SERVER -eq 1 ]]; then
|
||||||
echo "Starting index server.."
|
echo "Starting index server.."
|
||||||
python3 -m http.server
|
exec python3 /serve.py
|
||||||
else
|
else
|
||||||
echo "Skipping starting index server"
|
echo "Skipping starting index server"
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
import http.server
|
||||||
|
import socketserver
|
||||||
|
|
||||||
|
PORT = 8000
|
||||||
|
|
||||||
|
Handler = http.server.SimpleHTTPRequestHandler
|
||||||
|
|
||||||
|
|
||||||
|
def signal_handler(sig, frame):
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
|
|
||||||
|
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
||||||
|
print("serving at port", PORT)
|
||||||
|
httpd.serve_forever()
|
Loading…
Reference in New Issue