add more logging

This commit is contained in:
Karol Wypchlo 2022-02-08 12:22:49 +01:00
parent 967d9c24d1
commit 1a70fc97f7
No known key found for this signature in database
GPG Key ID: B515DE9EEBE241E1
3 changed files with 23 additions and 7 deletions

View File

@ -23,14 +23,15 @@ COPY bin bin
EXPOSE 3100
ENV NODE_ENV production
# 1. start dnsmasq in the background with:
# 1. get public server ip and save it in /etc/environment (passed to cron tasks as env variable)
# 2. start dnsmasq in the background with:
# - alias PORTAL_DOMAIN with current server ip so it overrides potential load balancer request
# - default docker nameserver 127.0.0.11 for any other request
# 2. replace docker nameserver with dnsmasq nameserver in /etc/resolv.conf
# 3. start crond in the background to schedule periodic health checks
# 4. start the health-check api service
# 3. replace docker nameserver with dnsmasq nameserver in /etc/resolv.conf
# 4. start crond in the background to schedule periodic health checks
# 5. start the health-check api service
CMD [ "sh", "-c", \
"serverip=$(node src/whatismyip.js) && \
"export serverip=$(node src/whatismyip.js) && \
echo \"export serverip=${serverip}\" >> /etc/environment && \
dnsmasq --no-resolv --log-facility=/var/log/dnsmasq.log --address=/$PORTAL_DOMAIN/$serverip --server=127.0.0.11 && \
echo \"$(sed 's/127.0.0.11/127.0.0.1/' /etc/resolv.conf)\" > /etc/resolv.conf && \

View File

@ -3,11 +3,20 @@ const { ipCheckService, ipRegex } = require("../utils");
const getCurrentAddress = async () => {
// use serverip env variable when available (set via Dockerfile)
if (process.env.serverip) return process.env.serverip;
if (process.env.serverip) {
if (ipRegex.test(process.env.serverip)) return process.env.serverip;
// log error to console for future reference but do not break
console.log(`Environment variable serverip contains invalid ip: "${process.env.serverip}"`);
}
try {
const { body } = await got(`http://${ipCheckService}`);
if (ipRegex.test(body)) return body;
if (ipRegex.test(body)) {
console.info(`Server public ip: ${body} (source: ${ipCheckService})`);
return body;
}
throw new Error(`${ipCheckService} responded with invalid ip: "${body}"`);
} catch (error) {

View File

@ -42,4 +42,10 @@ server.listen(port, host, (error) => {
if (error) throw error;
console.info(`Server listening at http://${host}:${port} (NODE_ENV: ${process.env.NODE_ENV})`);
const { ipRegex } = require("./utils");
if (ipRegex.test(process.env.serverip)) {
console.info(`Server public ip: ${process.env.serverip}`);
}
});