27

I'm trying to run the forever function for node.js but I get below warnings;

C:\serv>forever start SERVER.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up f
or at least 1000ms
info:    Forever processing file: SERVER.js

How to set --minUptime and --spinSleepTime to remove these warnings

Installed forever package with npm install forever -g

mujaffars
  • 1,395
  • 2
  • 15
  • 35
John
  • 271
  • 1
  • 3
  • 5

5 Answers5

22

These are only warnings. You could go on ignoring them, if you want. But if you want to explicitly set them, forever --help tells you how to do so. Just start forever with:

forever start --minUptime 1000 --spinSleepTime 1000 SERVER.js
Khôi
  • 2,133
  • 11
  • 10
  • 1
    But it don't load the file i thought the warnings needed to be fixed. And with your line i get CreateProcessW: Can't find the file while im in the folder where SERVER.js is placed – John Jul 23 '14 at 21:37
22

The documentation is not very exhaustive, a bit of additional information.

In the following examples we will use two scripts:

fail-fast.js:

process.exit(1);

fail-slow.js:

setTimeout(() => { process.exit(1); }, 2000);

1) using defaults

forever fail-fast.js

fail-fast.js script will execute only once, then no other start attempts will be made.

forever fail-slow.js

fail-slow.js script will be restarted indefinitely, as it stays up more than 1000ms (default value of minUptime if not specified). You can limit the number of restarts with the -m parameter.

2) setting only minUptime

forever --minUptime 10000 fail-fast.js
forever --minUptime 10000 fail-slow.js

Both fail-fast.js and fail-slow.js will be never be restarted, because we extended minUptime to 10 seconds and now fail-slow.js is considered spinning.

3) setting spinSleepTime

Whenever you set spinSleepTime (with or without minUptime), your process will restart even if it is considered 'spinning'.

forever --spinSleepTime 30000 fail-fast.js
forever --spinSleepTime 30000 fail-slow.js

Both scripts will be restarted forever, waiting spinSleepTime milliseconds between restarts.

Sidney
  • 4,495
  • 2
  • 18
  • 30
Dimitri De Franciscis
  • 1,022
  • 11
  • 20
  • You might want to clarify point (3). It will only restart if it fails. Obviously both of your scripts fail, but I don't think the difference is clear. – Cully May 13 '19 at 22:41
  • @Cully When you say it will only restart if it fails do you mean it wont anyhow restart when it does not exit? Is there a possibiilty where even with spinSleepTime, your script does not restart when it fails? Is there a specific type of failure where this can happen? – iWillGetBetter Jan 31 '20 at 03:41
4

In short:

When stop
    if hadRunTime >= minUptime 
       restart 
    else if spinSleepTime != 0
         wait spinSleepTime
         restart
    else 
         stop and no restart

@Megadix The answer has something wrong with spinSleepTime. fail-fast.js will restart wating spinSleepTime,but fail-slow.js will restart immediately,no waiting! It can be Proved by:

 console.log((new Date()).getTime());
 setTimeout(() => {
    process.exit(1);
   }, 2000);

output like:

1468812185697
error: Forever detected script exited with code: 1
error: Script restart attempt #1
1468812187766
error: Forever detected script exited with code: 1
error: Script restart attempt #2
1468812189834
error: Forever detected script exited with code: 1
error: Script restart attempt #3
1468812191901
error: Forever detected script exited with code: 1
error: Script restart attempt #4
1468812193977
error: Forever detected script exited with code: 1
error: Script restart attempt #5
1468812196039
error: Forever detected script exited with code: 1
error: Script restart attempt #6
1468812198107
error: Forever detected script exited with code: 1
error: Script restart attempt #7
1468812200172
error: Forever detected script exited with code: 1
0
forever start --minUptime 1234 --spinSleepTime 3421 SERVER.js

https://github.com/nodejitsu/forever#usage

jgillich
  • 71,459
  • 6
  • 57
  • 85
  • 3
    It gives me back `forever --minUptime 1000 --spinSleepTime 1000 SERVER.js` but it doenst load it – John Jul 23 '14 at 21:33
-1

I'm assuming you are using express module that is way after you using - forever start SERVER.js - your server is not running, because express module run server in path ./bin/www - so you should use this command - forever start ./bin/www --name="SERVER" - name is the name of your js file, by default app.js

cyprian
  • 497
  • 1
  • 6
  • 21