Skip to content

Commit

Permalink
Install pm2 for better handling of uncaught runtime errors (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
EarthlingDavey authored Dec 5, 2024
1 parent 01e6f92 commit 16aead8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ RUN chmod -R +x /docker-entrypoint.d/start-node-prod.sh
# Set the environment to production for install & runtime.
ENV NODE_ENV=production

# Install pm2 for better handling of uncaught runtime errors.
RUN npm install pm2 -g

# Install the node modules.
RUN npm ci --only=prod
RUN npm ci --only=prod

# Remove the npm package manager.
RUN apt remove -y curl npm unzip
Expand Down
4 changes: 2 additions & 2 deletions conf/entrypoint/start-node-prod.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

nohup node /usr/local/bin/node/server.js &

# pm2 will restart the node process on unhandled errors, `--no-daemon` will attach to application log
pm2 start /usr/local/bin/node/server.js --no-daemon &
1 change: 1 addition & 0 deletions conf/node/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const allowedTargetAgencies =

export const sensitiveFiles = [
"cookies.txt", // Contains the JWT and CloudFront cookies.
"hts-in_progress.lock", // Contains the JWT.
"hts-log.txt", // Has the httrack command line arguments - this includes the JWT.
`hts-cache/doit.log`, // Has the httrack command line arguments - this includes the JWT.
`hts-cache/new.zip`,
Expand Down
9 changes: 7 additions & 2 deletions conf/node/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ export const main = async ({ url, agency, depth }) => {

runHttrack(httrackArgs);

await waitForHttrackComplete(paths.fs);
const { timedOut } = await waitForHttrackComplete(paths.fs);

if (timedOut) {
console.error("Httrack timed out", { url: url.href, agency, depth });
return;
}

// Remove sensitive files - before syncing to S3
await Promise.all(
sensitiveFiles.map(file => fs.rm(`${paths.fs}/${file}`, { force: true }))
sensitiveFiles.map((file) => fs.rm(`${paths.fs}/${file}`, { force: true })),
);

// Sync the snapshot to S3
Expand Down

0 comments on commit 16aead8

Please sign in to comment.