Skip to content

Instantly share code, notes, and snippets.

@mrister
Last active November 16, 2023 16:24
Show Gist options
  • Save mrister/05d7c8fc061ad5a3fe883a330fe78040 to your computer and use it in GitHub Desktop.
Save mrister/05d7c8fc061ad5a3fe883a330fe78040 to your computer and use it in GitHub Desktop.
Forever example with config file
{
// Sample configuration for app in /home/myuser/app dir
"uid": "app",
"max": 5, // restart the app successively maximum of 5 times
"spinSleepTime": 1000, // time to wait until a next restart is attempted (in ms)
"append": true, // append the logs, do not overwrite
"watch": true, // watch for changes and restart if they occur
"script": "server.js", // main startup script (almost like issuing node server.js)
"sourceDir": "/home/myuser/app", // the dir where your entire app code resides (dir structure is recursively traversed)
"args": ["--myAPIKey", "xBlzdn84fa"] // pass any arguments to your app
}
#!/usr/bin/env bash
# install forever globally
npm i forever
# run forever with a config file
forever start /home/myuser/app/forever-config.json
# list running scripts with forever list
forever list
# checks logs with following command
forever logs
#restart all scripts should you need to
forever restart all
# stop running script with stop or stopall
# forever stopall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment