Add support for system crash/restart
See original GitHub issueI’ve been experimenting with Forever for some time and it is a great module. However I have a Debian server that sometimes hits memory limit and force restarts.
As the name implies, I’d have expected Forever to survive through system crash/restarts. I see that the documentation doesn’t state anything about system restarts, I’ve also done some testing on Windows too and there’s apparently no option to automatically restart it on system boot.
Did I overlook something, or do I have to actually add it to the system startup manually as an workaround? In that case, what would be a recommended approach e.g. adding the forever start script.js
line to a network script at /etc/network/if-up.d/
? And possibly a stop
command before that to don’t unnecessarily spawn multiple instances of the same script?
I’d like this live-through-restart/system crash to be a proper option in Forever, but if it can’t be, should I use the approach above or is there any better recommendations? As I’m using a VPS, a solution that doesn’t require root would be great.
Thanks in advanced.
Issue Analytics
- State:
- Created 11 years ago
- Comments:8
Top GitHub Comments
Yes, at least this VPS allows for Cron jobs. Here’s my slightly hackish solution, hopefully it may be useful to other node developers that may run into a similar issue:
(pardon me if the code style sucks, I’ve never had linux shell experience previously)
Execute a
echo "$PATH"
in the console and paste the returned string between the quotes inexport PATH=""
otherwise the script won’t work when running as a cron job.Of course, this
.sh
isn’t very sturdy due to relying on the string length of the message returned byforever list
. Any minor change to that message will break this script and it will have to be updated. Maybe a condition checking for a substring may be more sturdy:Still, it relies too much on a generic message. If there was only a way to obtain the number of running Forever instances it would be really useful for this use-case.
Nevertheless, after having saved the
.sh
above, create a Cron job for itcrontab -e
:Where 15 is the minutes interval between each check. I guess that’s it. Setting an e-mail is useful so you’d receive the echoed message(s) through e-mail whenever the script detects that no Forever instances are running, but e-mail could be set to an empty string to disable that feature as well.
Though, I’d like to know if it is possible to retrieve the number of running Forever instances in an easy way so I could eq it with
0
in the conditional? I guess simply returning the number of running instances wouldn’t be a hard feature to implement if it isn’t implemented yet.:)
Thanks again.
=]
Closing this as my issue has been resolved.