Skip to content

Commit

Permalink
fix(pm2): try to make pm2 reload/update all env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienjoly committed Dec 27, 2023
1 parent a58f1f3 commit b6662ee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/INSTALL.md
Expand Up @@ -129,7 +129,7 @@ If you don't want to use Docker (or can't), you can follow these instructions.

### Usage (advanced)

- Run `npm start`, or `npx pm2 start app.js` (auto-restart daemon)
- Run `npm start`, or `make start` (auto-restart daemon)
- Open [http://localhost:8080](http://localhost:8080) (or `WHYD_URL_PREFIX`)
- During development, you may have to restart the server to have your changes taken into account.

Expand Down
15 changes: 15 additions & 0 deletions ecosystem.config.js
@@ -0,0 +1,15 @@
const fs = require('fs');
const { loadEnvVarsFromString } = require('./test/fixtures.js');

module.exports = {
apps: [
{
name: 'openwhyd',
script: './app.js',
watch: false,
env: loadEnvVarsFromString(
fs.readFileSync('./env-vars-local.sh', 'utf8'),
),
},
],
};
2 changes: 1 addition & 1 deletion scripts/restart.sh
Expand Up @@ -22,4 +22,4 @@ echo "AUTH0_ISSUER_BASE_URL=${AUTH0_ISSUER_BASE_URL}"
DD_GIT_COMMIT_SHA="${GIT_COMMIT_SHA}" \
DD_GIT_REPOSITORY_URL="${GIT_REPOSITORY_URL}" \
WHYD_PORT=${PORT} \
npx --yes pm2 restart app.js --interpreter=${NODE} --update-env
npx --yes pm2 restart ecosystem.config.js --interpreter=${NODE} --update-env
2 changes: 1 addition & 1 deletion scripts/start.sh
Expand Up @@ -16,4 +16,4 @@ source env-vars-local.sh
DD_GIT_COMMIT_SHA="${GIT_COMMIT_SHA}" \
DD_GIT_REPOSITORY_URL="${GIT_REPOSITORY_URL}" \
WHYD_PORT=${PORT} \
npx --yes pm2 start app.js --interpreter=${NODE}
npx --yes pm2 start ecosystem.config.js --interpreter=${NODE}
8 changes: 6 additions & 2 deletions test/fixtures.js
Expand Up @@ -5,9 +5,9 @@ const childProcess = require('child_process');

const readFile = (file) => fs.promises.readFile(file, 'utf-8');

exports.loadEnvVars = async (file) => {
exports.loadEnvVarsFromString = (str) => {
const envVars = {};
(await readFile(file))
str
.split(/[\r\n]+/)
.map((line) => line.split('#')[0].trim()) // strip comments
.forEach((envVar) => {
Expand All @@ -18,6 +18,10 @@ exports.loadEnvVars = async (file) => {
return envVars;
};

exports.loadEnvVars = async (file) => {
return exports.loadEnvVarsFromString(await readFile(file));
};

exports.FAKE_ID = 'a0000000000000000000000a';

// inserted by config/initdb_testing.js
Expand Down

0 comments on commit b6662ee

Please sign in to comment.