Search code examples
node.jscentosdaemonupstart

Upstart script for nodejs daemon in CentOS doesn't work (crashes on start)


I have the following in a .conf file in the /etc/init/ directory of my CentOS server:

#!upstart
description "shortnr server for fmc.io"
author      "Felix Milea-Ciobanu"

start on startup
stop on shutdown

respawn
respawn limit 10 30

script
    export HOME="/root"
    exec /usr/local/bin/node /var/www/fmc.io/nodejs/app.js >> /var/www/fmc.io/logs/shortnr.upstart.log 2>&1
end script

pre-start script
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/www/fmc.io/logs/shortnr.upstart.log
end script

pre-stop script
    echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/www/fmc.io/logs/shortnr.upstart.log
end script

It's a pretty simple and straight forward upstart script. I named this service shortnr, after the nodejs software that the script starts up.

At the command line if I type in start shortnr I get something along the lines of shortnr start/running, process 28350.

However, I can't seem to access the nodejs server; If I do ps aux | grep shortnr at the command shell, nothing comes up.

If I do stop shortnr after running start, I get stop: Unknown instance:, meaning that the original service never started up.

The log file that I setup in the Upstart script looks something like this:

[2012-10-05T17:00:17.174Z] (sys) Starting
[2012-10-05T17:00:17.181Z] (sys) Starting
[2012-10-05T17:00:17.190Z] (sys) Starting
[2012-10-05T17:00:17.197Z] (sys) Starting
[2012-10-05T17:00:17.204Z] (sys) Starting

Basically the script is trying to start multiple times a second when I issued the start command, meaning that the service must be crashing on start or something and trying to respawn?

However, if I copy the command after exec and paste it in the shell prompt, the nodejs script starts up and runs properly.

So that means something must be wrong with my Upstart script.

If I try start/stop the service with the initctl command, I get the same results.

I'm running CentOS 6.3 and Upstart 0.6.5

Anyone have any idea what could be causing this or how to fix my script?


Solution

  • While I couldn't figure out the answer to my problem, I just ended up using forever instead: https://github.com/nodejitsu/forever-monitor