Skip to content

Commit

Permalink
fix(prod): Switch from forever to PM2
Browse files Browse the repository at this point in the history
to prevent "Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency"
fixes #151.
  • Loading branch information
adrienjoly committed May 1, 2021
1 parent 557964e commit e34c535
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ If you don't want to use Docker (or can't), you can follow these instructions.

### Usage (advanced)

- Run `npm start`, or `npm run forever:start` (auto-restart daemon)
- Run `npm start`, or `npx pm2 start app.js` (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
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
"semantic-release": "semantic-release",
"postinstall": "npm run -s donate; cp node_modules/playemjs/dist/playem-*.js public/js/",
"donate": "echo \"\n *** Thanks for downloading Openwhyd! ***\nPlease consider donating to our open collective\n\n => https://opencollective.com/openwhyd/donate\n\"",
"forever:stop": "npx forever stop app.js",
"forever:start": "mv appd.out prev.out; mv appd.err prev.err; npx forever --outFile appd.out --errFile appd.err --minUptime 1000 --spinSleepTime 500 --number 100000 start app.js $@",
"forever:restart": "npm run forever:stop; npm run forever:start $@;",
"start": "node app.js --fakeEmail --digestInterval -1 $@",
"start:coverage": "npx nyc --silent node app.js --fakeEmail --digestInterval -1 $@",
"test-reset": "node test/reset-test-db.js",
Expand Down
6 changes: 3 additions & 3 deletions scripts/restart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi
# Start Openwhyd's server
NEW_UID="openwhyd_$NEW_PORT"
PREV_UID="openwhyd_$PREV_PORT"
$ROOT_DIR/scripts/start.sh $NEW_PORT # will start app.js using forever
$ROOT_DIR/scripts/start.sh $NEW_PORT # will start app.js using pm2

echo "⏲ Waiting for Openwhyd..."
retries=0
Expand All @@ -46,7 +46,7 @@ do

if [ $retries -ge $MAX_RETRY ]; then
echo "⚠️ App is not responding. Killing it..."
npx forever stop 0
npx pm2 stop 0
# [TODO] Something like this would be better:
# cd $ROOT_DIR && npm stop -- $NEW_UID
echo "❌ Deployment failed."
Expand All @@ -63,7 +63,7 @@ sudo service nginx restart

echo "🌇 Stopping previous instance of Openwhyd..."
# Stop old server. Index 0 is always the oldest process.
npx forever stop 0
npx pm2 stop 0

# TODO: only do this if there was an oldest process,
# otherwise it will kill the server it just started!
Expand Down
2 changes: 1 addition & 1 deletion scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fi

# Start new server
echo "🌄 Starting Openwhyd with WHYD_PORT=$PORT..."
cd $ROOT_DIR && source env-vars-local.sh && WHYD_PORT=$PORT npm run forever:start -- --no-color &
cd $ROOT_DIR && source env-vars-local.sh && WHYD_PORT=$PORT npx pm2 start app.js

# TODO: find a way to identify that instance, e.g. -- "--uid openwhyd_$PORT"

0 comments on commit e34c535

Please sign in to comment.