zapty / forever-service

Provision node script as a service via forever, allowing it to automatically start on boot, working across various Linux distros and OS
https://github.com/zapty/forever-service
MIT License
594 stars 65 forks source link

setup process for nvm users #40

Closed kellyselden closed 8 years ago

kellyselden commented 8 years ago

Have you run across nvm user setup? My user path is

/home/vagrant/.nvm/versions/node/v5.1.0/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin

and my root path is

/sbin:/bin:/usr/sbin:/usr/bin

I've gotten this far after viewing #2:

sudo /home/vagrant/.nvm/versions/node/v5.1.0/bin/forever-service install taskrunner --script app.js --foreverPath /home/vagrant/.nvm/versions/node/v5.1.0/bin --foreverOptions " -c /home/vagrant/.nvm/versions/node/v5.1.0/bin/node" --runAsUser vagrant

but I still get /usr/bin/env: node: No such file or directory. It appears someone in the chain is still assuming node path for sudo.

arvind-agarwal commented 8 years ago

@kellyselden actually when you do runasuser internally one more file is executed get-forever-config, I think that is what is causing the issue. I will require some code changes in forever-service executable to execute get-forever-config with the correct node path. If you can send me a pull request I will be happy to accept it.

kellyselden commented 8 years ago

I don't think this is exclusively a runAsUser issue. I took it out and got the same error

sudo /home/vagrant/.nvm/versions/node/v5.1.0/bin/forever-service install taskrunner --foreverPath /home/vagrant/.nvm/versions/node/v5.1.0/bin --foreverOptions " -c /home/vagrant/.nvm/versions/node/v5.1.0/bin/node"

/usr/bin/env: node: No such file or directory

arvind-agarwal commented 8 years ago

Have you tested just plain forever with nvm? Did it work?

kellyselden commented 8 years ago

Yes, that works because I don't have to run it with sudo. The problem I think is the nvm doesn't put anything in the root PATH.

arvind-agarwal commented 8 years ago

Looks like issue is due to sudo running as a totally different environment (root), when you are executing forever or forever-service as non sudo, you might have already done nvm use specific version of node. And hence node executable is in the path. However when you run as sudo it is unable to find forever-service itself since in sudo no nodejs is in path.

I would recommend if you do want to use nvm, have only one version of nodejs for running services. And setup symlink to node executable for all global executables such as forever, forever-service

ln -s /home/vagrant/.nvm/versions/node/v5.1.0/bin/node /usr/bin/node ln -s /home/vagrant/.nvm/versions/node/v5.1.0/bin/forever /usr/bin/forever ln -s /home/vagrant/.nvm/versions/node/v5.1.0/bin/forever-service /usr/bin/forever-service

Once you have setup these you can run forever-service normally without getting into hassle of specifying complete path. And still use nvm to install modules without sudo.

arvind-agarwal commented 8 years ago

@kellyselden did this work for you?

kellyselden commented 8 years ago

This worked. Thank you very much.

moviedo commented 8 years ago

@arvind-agarwal @kellyselden Thanks for solving this issue. Solved my forever-service with local-npm problem.

sudo forever-service install local-npm-service --script /home/vagrant/.nvm/versions/node/v4.2.6/lib/node_modules/local-npm/lib/bin.js  -o " -d /home/vagrant/.local-npm" --foreverPath /home/vagrant/.nvm/versions/node/v4.2.6/bin --start