Can't make something run at boot using rc.d

I'm trying to start a Node.js application at system boot, using PM2 (PM2 is something like Forever, it 's just a process manager for Node). It's not starting automatically on bootup, but I can start it manually if I run # /usr/local/etc/rc.d/nodejs start. Here is my rc.d script (/usr/local/etc/rc.d/nodejs):

Code:
#!/bin/sh

# PROVIDE: nodejs
# REQUIRE: NETWORKING
# KEYWORD: shutdown

name="nodejs"

. /etc/rc.subr

rcvar="${name}_enable"
start_cmd="${name}_start"
stop_cmd=":"

nodejs_start()
{
        /usr/node/node_modules/.bin/pm2 start /usr/node/app.js -i max --name my-node
}

load_rc_config $name
run_rc_command "$1"

The relevant lines in my rc.conf (/etc/rc.conf):
Code:
rc_debug="YES"
nodejs_enable="YES"

Here's the output from the log (/var/log/messages):
Code:
Jul 15 09:32:42 sugo-node root: /etc/rc: DEBUG: checkyesno: nodejs_enable is set to YES.
Jul 15 09:32:42 sugo-node root: /etc/rc: DEBUG: run_rc_command: doit: nodejs_start

I'm hoping there is just a simple oversight somewhere. I've even tried the fallback of running this as a cron job with the @reboot statement, but even that didn't work.
 
My solution in the end, although a cop-out, was to use Nginx instead. I trialed it for other reasons and it did the job, as I'm only hosting some static files for a LAN based project. It's possibly better suited to that basic task than Node.js anyway. The Nginx port comes with functional rc.d scripts which was a welcome bonus.
 
I know it's a late response, and perhaps not of very much use to you, but I couldn't help noticing that I missed out a very important part in your test case up there...

Although you tested the script by manually running it you didn't test how the "rc.d structure" responded to it. So in your case above I would have expected you trying to run: # service nodejs start and then check what happened. Optionally also trying # service nodejs status.

Of course I can't be sure, but something tells me that the output of that command might have given you some hints to sort this out.
 
Back
Top