What's the right way to start a node.js service?

I'm running a node.js service (statsd) on CentOS 6. What's the proper way to daemonize and start such a service?

Potential Daemonizers--are daemonizers supposed to be language-specific or general?:

  • forever (node-specific)
  • daemonize
  • nohup (presumably wrong)
  • start-stop-daemon(debian-only? is this for daemonizing or starting/stopping? what is the Centos equivalent?)
  • Should the app itself really know how to daemonize itself and then have a -d flag? (e.g. via node-daemonize2 or forever-monitor?)

Service starters--should these be from the system/distro, or should they be from monitoring tools such as monit?:

  • service? is really /etc/init.d on CentOS?
  • service? is really Upstart on Ubuntu?
  • monit?
  • daemontools?
  • runit?

I'm unfortunately new to this--where can I read up on what is the most standard, classic, reliable way of doing this?


Should the app itself really know how to daemonize itself...

If your app is meant to be run as a daemon, yes, it should be fully aware of how to daemonize itself, write the appropriate files (log and PID spring to mind), and handle signal. Big WTF if this isn't the case.

If your app isn't really meant to be daemonized, or that's not it's primiary purpose, then it's your decision completely. If you want to make it easy for others, you'll probably add it. If you want to make life easier on yourself, you'll probably leave it out. People generally wont have a "WTF" response either way.

Service starters...

Each distro's packages/ports system should be responsible for modifying your generic start/stop scripts to meet their particular needs. This stuff generally ain't rocket science, but when in doubt contact the maintainers for the distro you're working on.

Monitoring tools..

Should know how to interact with the Distro's official start/stop mechanisms, and should have no idea how to interact with your program specifically (unless your program "publishes" data through a reporting mechanism, possibly including hooks for a SNMP service or similar; all this really depends on what your program does though).