2
votes

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?

2

2 Answers

0
votes

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

0
votes

I am also running into similar problems on CentOS 6.3, Upstart 0.6.5 and Node.Js 0.10.5. I specifically upgraded Node so I could use the daemon module and be able to put the daemonized Node app under Upstart control.

Here's my /etc/init/job-worker.conf:

description "job-worker under Upstart/init control"

start on job-worker-start-event
stop on job-worker-stop-event

expect daemon

script
  #setuid myuser
  exec /root/BasicJobWorker/bin/basic-job-worker
  #sleep 5
end script

respawn
respawn limit 10 5 

And here's my basic-job-worker script:

\#!/usr/bin/env node

// this code is run twice
// see implementation notes below
console.log(process.pid);

// after this point, we are a daemon
require('daemon')();

// different pid because we are now forked
// original parent has exited
console.log(process.pid);

var BasicJobWorker = require('../lib/basic-job-worker.js');

new BasicJobWorker().boot();

I have tried using "expect fork", "expect daemon" as well as no expect at all. In all cases the job is respawned too fast and it is eventually stopped.