Search code examples
node.jsubuntucronforever

nodejs app with forever in cronjob does not work after reboot


I created a cronjob with sudo crontab -u USERNAME -e and tried to start my node.js app after each reboot.

It had worked well at another server.

But this time, I installed the Node.js via nvm

Then tried to run the same cronjob lines, but every time after reboot it failed. I tried to figure out all the related folders and tried again to run as different lines. When I check with forever list, server shows that no process is running.

@reboot /home/USERNAME/.npm/forever start -c /home/USERNAME/.nvm/current/bin/node  /home/USERNAME/APPNAME/app
@reboot /home/USERNAME/.npm/forever start  /home/USERNAME/APPNAME/app
@reboot /usr/local/bin/forever start -c /home/USERNAME/.nvm/current/bin/node  /home/USERNAME/APPNAME/app

I think that the reason is somehow related with nvm. But I am not sure of that. I don't want to do anything unnecessary unless I am fully sure about it.


Solution

  • Edited July 26, 2015

    Though I have used the npm's forever module to deploy nodejs production apps, I really do not see the need to use it on linux based servers as there are so many system level alternatives available.

    One of them is upstart. It will help you run your scripts as system level services. Amazon Web Services also use upstart in their Elastic Beanstalk nodejs tiers to keep nodejs apps running forever.

    If you really just need to get down to it, here is a link to run your nodejs app as an upstart service.

    However, it is not limited to deploying nodejs apps only and if you learn upstart, you will be able to do a lot of things with it. Here is a link for that as well.