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

7
  • 1
    Why do you need to change them? Commented Jul 23, 2014 at 21:20
  • Because i get the error in the description
    – John
    Commented Jul 23, 2014 at 21:33
  • 1
    That's not an error, 'warn' means it's a warning which you can choose to ignore. Commented Jul 23, 2014 at 22:30
  • But this wont load the js file when i look at forever list nothing will showed up
    – John
    Commented Jul 23, 2014 at 22:33
  • Well that's another problem. Your script is crashing. You don't want to prolong it if it's got a bug, you want it to crash. Try running with node SERVER.js and fix the bug first before starting it with forever. Commented Jul 23, 2014 at 22:35

5 Answers 5

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
1
  • 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
    Commented Jul 23, 2014 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.

2
  • 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
    Commented May 13, 2019 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? Commented Jan 31, 2020 at 3: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

1
  • 3
    It gives me back forever --minUptime 1000 --spinSleepTime 1000 SERVER.js but it doenst load it
    – John
    Commented Jul 23, 2014 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

1
  • The errors they are referring to are just warnings. @cyprian
    – FabricioG
    Commented Jun 11, 2019 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.