1

I cant put my crontab to work. I'm on Ubuntu 14.04x64

So, this is what I did:

.root
.pw
.sudo apt-get update
.sudo apt-get install nodejs
.sudo apt-get install npm
.curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash

[I reload Putty]

.nvm install 0.12
.npm install steam

[Now I go to filezilla, upload the file.js into root directory]

.nvm use 0.12
.node file.js

[It executes the file.js sucessfuly, I reload Putty]

.nvm use 0.12
.npm install forever -g
.forever start file.js

[It will execute the file.js infinitely]

Now I want a restart to execute this commands. The thing is that "forever start" will not execute if I dont execute the "nvm use 0.12" in first place.

So:

.crontab -e

nano

.*/5 * * * * nvm use 0.12 && forever restart file.js

ctrl + x saved

Result: It doesn't restarts.

What I'm doing wrong? Thanks!

1
  • 1
    why don't you create a bash file and just execute that in the cron? – MiPnamic Jun 9 '15 at 10:50
1

Found the solution myself.

0 * * * * root/.nvm/v0.12.4/bin/node /usr/local/bin/forever restart file.js

Thanks anyway! :)

0

For starters, it is likely that your cron does not have a default environment and therefore you need to specify full path's for commands and files.

As @MiPnamic says, best to wrap your startup into a shell file and execute that instead. That also makes it easier to adjust should you need to - for example if you want to change from Node 0.12 to 0.10 or something else.

In addition, you can also set the default version in NVM by doing:

nvm alias default v0.12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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