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
595 stars 65 forks source link

Error: Forever detected script excited with code: 0 #31

Closed ghost closed 9 years ago

ghost commented 9 years ago

Getting this error when trying to install a service, as well as get status, or remove it.

Can't find anywhere that explains this error, and have even seen other forum posts with similar errors but with codes null, 8, etc.

Can you help identify the problem?

arvind-agarwal commented 9 years ago

Please provide your environment details, and also command you have used to provision the service, also have you tried this with latest release of forever and forever-service?

ghost commented 9 years ago

I'm using a RaspberryPi using Debian (from the Domoticz SD card image). The command I'm using is forever-service install -s mqtt.js sky-plus-hd-mqtt (I have already cd to the directory the js file is in). And I assume I'm using the latest release? 0.5.1? There's nothing to upgrade when I do apt-get

arvind-agarwal commented 9 years ago

What is version of forever? Have you npm installed latest forever version? and what version of node it has?

ghost commented 9 years ago

I believe these are my versions: Forever: 0.14.2 Node: 0.12.1

arvind-agarwal commented 9 years ago

node --version forever --version

arvind-agarwal commented 9 years ago

Also where are you getting the above error message?

ghost commented 9 years ago

After I use forever-service install -s mqtt.js sky-plus-hd-mqtt

arvind-agarwal commented 9 years ago

can you dump full output here

ghost commented 9 years ago

No sorry, when i install the service i get:

forever-service version 0.5.1

Platform - Raspbian GNU/Linux 7 (wheezy)
Could not provision service
Service is already present
ghost commented 9 years ago

But after I run sudo service sky-plus-hd-mqtt start (or stop, delete or status) I get the following:

error: Forever detected script exited with code: 0 error: Script restart attempt #1 error: Forever detected script exited with code: 0 error: Script restart attempt #2 error: Forever detected script exited with code: 0 error: Script restart attempt #3

And this just loops

arvind-agarwal commented 9 years ago

node & forever version?

ghost commented 9 years ago

I've already given you those: Forever: 0.14.2 Node: 0.12.1

arvind-agarwal commented 9 years ago

http://stackoverflow.com/questions/29276996/node-js-and-forever-exited-with-code-0

ghost commented 9 years ago

I have already seen that, I can't see how it applies to me though. Is there nothing you can help with?

arvind-agarwal commented 9 years ago

Are you able to run your script by just running forever start mqtt.js?

ghost commented 9 years ago

Mainly, I want to know what the error code means

arvind-agarwal commented 9 years ago

You will have to open issue in forever github

ghost commented 9 years ago

$ forever start mqtt.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: mqtt.js

ghost commented 9 years ago

Are you able to tell me where you think the issue is? Whether it's in Forever, or Forever-service, or somewhere else?

arvind-agarwal commented 9 years ago

It is with forever since forever-service has provisioned the service..

ghost commented 9 years ago

Okay, thanks

arvind-agarwal commented 9 years ago

https://ghost.org/forum/installation/17680-unable-to-keep-ghost-up-and-running-with-forever-or-pm2-error-unable-to-access-ghost-s-content-path/ It could be related to permissions also..

ghost commented 9 years ago

I've seen that also. But can you actually tell me what the error code 0 means.....?

arvind-agarwal commented 9 years ago

As i said i have no idea, just trying to help out. Why dont you open issue in forever also.

ghost commented 9 years ago

https://github.com/foreverjs/forever/issues/725 - If you could help with this issue, I'd greatly appreciate it. You might have more knowledge and info to give.

arvind-agarwal commented 9 years ago

@leecollings were you able to resolve this?

ghost commented 9 years ago

Nope, haven't heard anything back from my issue in the Forever script. From the looks of it, they don't answer hardly any of their issues. The guy who was helping me in the first place also seems to have gone quiet. So right now, I'm at a bit of a roadblock.

Regards,

Lee

On 7 July 2015 at 15:07, Arvind Agarwal notifications@github.com wrote:

@leecollings https://github.com/leecollings were you able to resolve this?

— Reply to this email directly or view it on GitHub https://github.com/zapty/forever-service/issues/31#issuecomment-119213665 .

arvind-agarwal commented 9 years ago

ok, to debug it further please see if you have any logs in /var/log/sky-plus-hd-mqtt.log file. If it is, post it here.

ghost commented 9 years ago

No, that log file doesn't exist. However in the /var/log folder I have another folder called Mosquitto, within that there is a general mosquitto.log if that's helpful?

Regards,

Lee

On 7 July 2015 at 15:19, Arvind Agarwal notifications@github.com wrote:

ok, to debug it further please see if you have any logs in /var/log/sky-plus-hd-mqtt.log file. If it is, post it here.

— Reply to this email directly or view it on GitHub https://github.com/zapty/forever-service/issues/31#issuecomment-119219269 .

arvind-agarwal commented 9 years ago

check you /var/log/messages and see after boot you see any messages related to this service..

ghost commented 9 years ago

Jul 7 15:32:11 domoticz domoticz: Domoticz is starting up.... Jul 7 15:32:11 domoticz domoticz: Domoticz running... Jul 7 15:33:00 domoticz kernel: [ 57.809247] w1_master_driver w1_bus_master1: Family 0 for 00.800000000000.8c is not registered.

(The last message, appears many times through the messages list - Although this could be because I have test devices set up in Domoticz, that don't have proper IDs.) But apart from that, that's the only messages on there.

Regards,

Lee

On 7 July 2015 at 15:30, Arvind Agarwal notifications@github.com wrote:

check you /var/log/messages and see after boot you see any messages related to this service..

— Reply to this email directly or view it on GitHub https://github.com/zapty/forever-service/issues/31#issuecomment-119222017 .

arvind-agarwal commented 9 years ago

Can you put a console.log test message in your script in the beginning and then check if it generates the /var/log/sky-plus-hd-mqtt.log log file when starting the service.

ghost commented 9 years ago

So I added console.log("Test"); at the start of the mqtt.js file, and attempted to start the service by sudo service sky-plus-hd-mqtt start.

I received the Error code:0 message, and checked the log file, and it still doesn't exist.

Regards,

Lee

On 7 July 2015 at 15:37, Arvind Agarwal notifications@github.com wrote:

Can you put a console.log test message in your script in the beginning and then check if it generates the /var/log/sky-plus-hd-mqtt.log log file when starting the service.

— Reply to this email directly or view it on GitHub https://github.com/zapty/forever-service/issues/31#issuecomment-119223803 .

denniskenny commented 9 years ago

I'm running Ghost on RaspberryPi and I'm seeing the same error. I would like to just be able to delete the failing service but 'forever-service' delete fails too.

root@pi:/home/dennis/ghost# forever-service delete ghost forever-service version 0.5.2

Platform - Raspbian GNU/Linux 7 (wheezy) Shutting down ghost: error: Forever detected script exited with code: 0 error: Script restart attempt #1 error: Forever detected script exited with code: 0 error: Script restart attempt #2 ...

arvind-agarwal commented 9 years ago

Can you provide a script to replicate this issue in Centos / Debian?

denniskenny commented 9 years ago

I'm using Raspbian (3.18.7-v7+ armv7l GNU/Linux) and the script is the GhostJs launch script; https://github.com/TryGhost/Ghost/blob/master/index.js

arvind-agarwal commented 9 years ago

@denniskenny are you able to replicate it in Centos / or Debian? I cant debug in Raspbian..

denniskenny commented 9 years ago

Both @leecollings and myself are using GhostJs on Raspbian, so it may be specific to that build or app. Let me know if there are further steps or logs I can post here. I'll keep digging.

houmark commented 9 years ago

I'm also seeing error: Forever detected script exited with code: 0 but I'm using Amazon Linux AMI. Running latest forever 0.15.1 and latest forever-service 0.5.3. I've made sure that both forever and forever-service are installed globally.

I've tried all kinds of things, and have some 5 apps running on the system, and none of them are able to start as a service.

This is hard to debug, because the only error I get is the one above. I've tried the newish --runAsUser but that did not change anything, same error.

@leecollings @denniskenny have you been able to make this work in any way?

houmark commented 9 years ago

And just wanted to add that starting any of the 5 apps using forever either using sudo or normally as the ec2-user, starts them and runs overall super stable. 4 of them are Express based apps, the last one is a super simple http test app, that includes the below:

var http = require('http');

http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('testing. . .\n');
}).listen(3000);

console.log('Server running');
arvind-agarwal commented 9 years ago

@houmark how did you install nodejs on Amazon Linux? I am trying to debug this, I have personally 50+ instances in Amazon linux running with forever-service and have never faced this issue. So this is kind of strange, are you able to replicate this issue in a brand new Amazon Linux instance also? If yes, could you share the instance initialisation code, so that I can replicate the issue in my environment.

houmark commented 9 years ago

@arvind-agarwal That's a good question. I've been tweaking everything on the server, but the very first install, including nodejs, was done by a college, so I'm not completely sure. Can you point me to anything I can check for reference? nodejs relies in /usr/local/bin/node - sudo is required for global install (have been looking at adding that folder to the sudoers configuration but haven't done it yet).

houmark commented 9 years ago

@leecollings Not sure why this one was closed now?

In the meantime I was looking more into our current node installation and it seems like the node source was downloaded to the /home/ec2-user/node and then make install from there to its final location /usr/local/bin/node, as mentioned before. Is there a more recommended way? I also saw a recommendation to install using yum (which is how everything else on the server is installed): sudo yum install nodejs npm --enablerepo=epel.

@arvind-agarwal What is your recommended way, so I can try to reinstall node in that way? This will be our first production system on AWS with node.js so we don't have much experience in setting it up. Maybe this use case can help tweak either how forever-service runs or some improved docs on how node should be running on Amazon Linux in order for it to work.

houmark commented 9 years ago

And here follows some more information about our EC2 install:

node.js is installed using make install after downloading the official source. Version is 0.12.4. make test runs and completes all tests with no errors found. The etc/sudoers includes (and has always included) /usr/local/bin so nothing to change here in as I see it.

To me it seems like node.js is installed perfectly fine and should not be the issue here. So then the question goes to what we can look at then? I'm curious to hear how you install node.js on your EC2 instances. I would like to try installing a new isolated fresh instance up, but will be awaiting your feedback before attempting that.

arvind-agarwal commented 9 years ago

@houmark can you try to run with -e param to specify the path -e "PATH=/usr/local/bin:\$PATH".

Look at #28 for sample

houmark commented 9 years ago

@arvind-agarwal Thanks for you feedback.

Unfortunately I get the same result. The service gets provisioned without problems (it always did), but starting it is a problem:

[ec2-user@ip-xxx-xxx-xxx-xxx test]$ sudo forever-service install testing -s /var/www/test/app.js -e "PATH=/usr/local/bin:\$PATH"
forever-service version 0.5.3

Platform - Amazon Linux AMI release 2015.03

testing provisioned successfully

Commands to interact with service testing
Start   - "sudo service testing start"
Stop    - "sudo service testing stop"
Status  - "sudo service testing status"
Restart - "sudo service testing restart"
[ec2-user@ip-xxx-xxx-xxx-xxx test]$ sudo service testing start
error: Forever detected script exited with code: 0

I also tried without the -s parameter, but with the same result.

Added: Only killing with CTRL + C gets me out of that situation and it's the same situation if I try to delete the service. So I'm using a new unique name every time, and manually delete them by removing the script and symlink manually.

arvind-agarwal commented 9 years ago

@houmark try one more thing, change directory to /var/www/test directory and than provision the script and see if it has better result

cd /var/www/test sudo forever-service install testing -s app.js -e "PATH=/usr/local/bin:\$PATH"

houmark commented 9 years ago

Unfortunately that's exactly what I did...

houmark commented 9 years ago

I will try again, I see you did -s app.js which I did not try specifically.

arvind-agarwal commented 9 years ago

Do you see anything in /var/log/testing.log?