2

I need some help with this; endless upon endless scripts look exactly the same -- yet I can't seem to stop the job associated with an upstart script. I'm using any of the newest Ubuntu Elestic AMIs on EC2, and it happens from micro to large instances.

At first, I hand a simple configuration in /etc/init/node-monitor.conf to start a process:

description "node-monitor"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
exec sudo -u root sh -c "cd /home/ubuntu/node-monitor/run && /usr/local/bin/node client.js ec2=true debug=false console=true cloudwatch=true >> /var/log/node-monitor.log 2>&1 &"

This worked for starting:

sudo start node-monitor
node-monitor start/running, process 1580

But not stopping:

sudo stop node-monitor
stop: Unknown instance: 

Then I tried something more complicated, based on another node.js project:

description "node-monitor"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
script
echo $$ > /var/run/node-monitor.pid
exec sudo -u root sh -c "cd /home/ubuntu/node-monitor/run && /usr/local/bin/node client.js ec2=true debug=false console=true cloudwatch=true >> /var/log/node-monitor.log 2>&1 &"
end script
pre-stop script
rm /var/run/node-monitor.pid
end script

But this didn't work either. What in Sam Hill am I doing wrong?

  • `whereis stop`, `locate stop` and `find / stop` can be your friends. – mailq Jan 14 '12 at 20:07
  • Ummm....not the point. `/sbin/stop exists`. I can tab-complete `start node-m`, I can't tab-complete `stop node-m` -> almost like something is missing in the Upstart job. –  Jan 14 '12 at 21:39

1 Answers1

0

So first off, upstart runs all jobs as root, so you don't need sudo, get rid of that.

Second, it would appear that your monitored program is exitting, hence the 'unknown instance' error. You should get something in /var/log/syslog telling you that the process exitted. You can add the word 'respawn' and upstart will try to start it back up again, but if it keeps exitting rapidly, upstart will give up eventually.

You are ending your line with &, which means "run this in the background". Given that, upstart will see that your shell exit (since job control is not active in a non-interactive shell, & will effectively daemonize any jobs). If you want upstart to keep this process running, and to be able to kill it, drop the &.

Also, your start on is way too explicit, and your stop on is based on an event that doesn't exist. You can just start on runlevel [2345], and stop on runlevel [^2345], and that will help your job work better in later releases as Ubuntu evolves. As of Ubuntu 11.10, it also means that it will start after all network interfaces are up, not just eth0.

More fun, you can use the 'chdir' stanza, so you don't have to use a shell at all.

So the original job is best written as:

start on runlevel [2345]
stop on runlevel [^2345]

respawn
chdir /home/ubuntu/node-monitor/run
exec /usr/local/bin/node client.js ec2=true debug=false console=true cloudwatch=true >> /var/log/node-monitor.log 2>&1

For bonus points, when Ubuntu 12.04 is released, you can use the new 'console log' feature and take out the >> /var/log/node-monitor.log , though it will write to /var/log/upstart/node-monitor.log instead.

And finally, there are no actual "alestic" AMI's anymore. Eric Hammond keeps a table of the same AMI ids which are listed on https://cloud-images.ubuntu.com.. compare http://alestic.com to http://cloud-images.ubuntu.com/query/lucid/server/released.current.txt for instance.

SpamapS
  • 348
  • 1
  • 8