Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dreamhost Cron Job not restarting Forever #58

Closed
spadeworkers opened this issue May 16, 2011 · 11 comments
Closed

Dreamhost Cron Job not restarting Forever #58

spadeworkers opened this issue May 16, 2011 · 11 comments

Comments

@spadeworkers
Copy link

I have a cronjob set up on my Dreamhost vps account to check if node.js is running a specific script with Forever. The cron first loads the user environment by loading the /path/to/.bash_profile, then runs the php script which checks to see if forever is running the given node.js script: /path/to/check_node_app.php -s application_search.js. This php script runs the shell command forever list, checks for the script, then runs forever start if its not running. (the main reason for creating this script is because forever shut down once, maybe due to server reboot??)

software versions:
forever: 0.4.1
node: v0.4.4
npm: 0.3.15
OS: Linux ps39832 2.6.33.7-vs2.3.0.36.30.4 #23 SMP Tue Sep 28 05:47:35 PDT 2010 x86_64 GNU/Linux

It works perfectly if I run the php script from the command line of that user, but from the cron job, it spits out the error:

sh: forever: command not found

Then if I put the full path to forever in the script /usr/local/lib/node/.npm/forever/0.4.1/package/bin/forever I get this error:

sh: forever: command not found
/usr/bin/env: node: No such file or directory

I chose php for the script basically because I know php and not bash very well, though if this causes part of the issue I am fine to learn how to do it in bash. If there is nothing off the bat here that seems obvious is the issue, I'll update forever as Charlie suggested in an email from him.

@spadeworkers
Copy link
Author

I went ahead and started the same script in bash, and the script successfully finds the forever command, but not node:

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

Anyone have an ideas?

@AvianFlu
Copy link
Contributor

AvianFlu commented Jun 8, 2011

@spadeworkers: your individual user account seems to have a node path set in your bash environment, but the user trying to run the cron job, sometimes a separate cron user, doesn't. You could either try to change the path settings for the cron user, or only give cron fully qualified paths.

Let me know if this is still a problem or if you have other questions.

@spadeworkers
Copy link
Author

Thanks for the response. I realize I should have added the -c argument to the command adding the full path to the node app. Though even after I did that I am still getting the node error. Even the list command returns the same error. The command I'm running is:

/usr/local/lib/node/.npm/forever/0.4.1/package/bin/forever -v -c /home/xxxxx/node/node list

Error is:

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

Its as if the -c argument is not working.

@indexzero
Copy link
Member

@spadeworkers The -c option is only for the executable that you want any processed to be spawned with. The problem is here (I suspect): https://github.com/indexzero/forever/blob/master/bin/forever#L1

I'm not sure the best way to make this run across multiple possible node locations. @AvianFlu do you know if its possible to replace:

#!/usr/bin/env node

with something like:

#!which node

@AvianFlu
Copy link
Contributor

AvianFlu commented Jun 8, 2011

@indexzero: it would have to be #! /usr/bin/which node , but I don't otherwise see a problem.

@indexzero
Copy link
Member

@AvianFlu This doesn't seem to work. I modified and linked my local forever and tried forever list. The output was unexpected and is below:

$ forever list
/usr/local/bin/node
/usr/local/bin/forever

@indexzero
Copy link
Member

@spadeworkers I believe I have found a solution to your problem. Can you try running

  $ node `which forever` list

I'm not sure the right approach to fixing this in forever core. A comment from anyone with serious bash-fu would be welcome.

@AvianFlu
Copy link
Contributor

I have encountered the same - which used in a hashbang results in the string, rather than the command being executed.

/usr/bin/env actually adds node to the environment before running it - provided the shell in question has something useful to associate the word node with. The real question is how to make sure node is in a given user's path so that the shell knows what to do.

@AvianFlu
Copy link
Contributor

Having one's absolute node path in the hashbang would work for this. #!/usr/bin/node or what have you.

@spadeworkers
Copy link
Author

@indexzero I ran the command you suggested:

node `which forever` list

and it works fine from the command line, but then I had this run from the cron:

/usr/local/bin/node `which forever` list

and I get this error:

node.js:134
   throw e; // process.nextTick error, or 'error' event on first tick
   ^
Error: Cannot find module '/home/xxxxx/list'
   at Function._resolveFilename (module.js:320:11)
   at Function._load (module.js:266:25)
   at Array.<anonymous> (module.js:423:10)
   at EventEmitter._tickCallback (node.js:126:26)
1

'/home/xxxxx/' is the home folder for the user under which the cron job is running

@indexzero
Copy link
Member

This should be fixed in the 0.6.x branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants