foreversd / forever

A simple CLI tool for ensuring that a given script runs continuously (i.e. forever)
http://github.com/foreverjs/forever
MIT License
13.86k stars 946 forks source link

How to run forever after rebooting server? #997

Open kselax opened 6 years ago

kselax commented 6 years ago

Hello! I tried to run node.js after reboot, put to crontab -e next command

@reboot /home/neo/.nvm/versions/node/v8.11.2/bin/forever start -c /home/neo/.nvm/versions/node/v8.11.2/bin/node /var/www/american-chat.ru/index.js; echo "neo reboot: date" >> /home/neo/test.crontab /1 * /home/neo/.nvm/versions/node/v8.11.2/bin/forever start -c /home/neo/.nvm/versions/node/v8.11.2/bin/node /var/www/american-chat.ru/index.js; echo "neo every minute: date" >> /home/neo/test.crontab

and see nothing. Crontab can't run forever after reboot nor each minute. How to run forever after rebooting the server?

These commands perfectly work if I do it manually in a terminal

neo@kselax:~$ neo@kselax:~$ /home/neo/.nvm/versions/node/v8.11.2/bin/forever start -c /home/neo/.nvm/versions/node/v8.11.2/bin/node /var/www/american-chat.ru/index.js; warn: --minUptime not set. Defaulting to: 1000ms warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms info: Forever processing file: /var/www/american-chat.ru/index.js neo@kselax:~$

kselax commented 6 years ago

oh, I've solved it. it wasn't forever problem. It is bad knowledge how to use crontab. We to run crontab much better using your own script where you can explicitly to define environment variables

I've made this script script.sh `#!/bin/bash PATH=/home/neo/.nvm/versions/node/v8.11.2/bin/

/home/neo/.nvm/versions/node/v8.11.2/bin/forever start -c /home/neo/.nvm/versions/node/v8.11.2/bin/node /var/www/american-chat.ru/index.js &>> /home/neo/test.crontab ` and now everything works. simply command won't works, because we need to specify bash, we need to specify a path to node.js. with cronetab they seems to be absence.

ghost commented 3 years ago

Hi I have the same problem trying to start forever after @reboot, doesnt't work even after I put this to script

!/bin/bash

cd ~/lacirolnikdev && sudo ~/.nvm/versions/node/v14.13.1/bin/forever start -c "/.nvm/versions/node/v14.13.1/bin/npm start" . cd ~/coinwork && sudo ~/.nvm/versions/node/v14.13.1/bin/forever start -c "/.nvm/versions/node/v14.13.1/bin/npm start" .

forever list is emty, can you help?