92bondstreet / initd-forever

🏚️ Node.js module to create a daemon for your nodejs application.
49 stars 21 forks source link

express handlebars initi.d #18

Closed vevmesteren closed 8 years ago

vevmesteren commented 8 years ago

This is not directly related, but the issue I am experiencing only happens when I start the app through the generated init.d entry.

When I start the application manually like so

forever bin/www

all is well, and res.render works charmingly and as expected.

When I start the app through the service though,

views-engine is setup and configured like so

app.set('views', path.join(__dirname+'/views/'));
app.engine('handlebars',require('express-handlebars')({defaultLayout:'main', extname: '.handlebars'}));
app.set('view engine','handlebars');

console.log(__dirname) outputs

/myapp/

in both cases, so it seems that the app knows where it's at. Just trying to drill myself in there to figure out if it's express-handlebars that breaks or if it's due to the app running through the service.

Here is the error

Error: ENOENT: no such file or directory, open '/views/layouts/main.handlebars'
   at Error (native)

The file is there, and renders perfectly find when not app is run directly rather then service.

Any pointers whatsoever would be great

thanks

vevmesteren commented 8 years ago

UPDATE When I run

#forever /myapp/bin/www

from root I get the same issue.

when I do

#cd /myapp
#forever bin/www

it works as expected, seems that forever and paths don't play nice.

vevmesteren commented 8 years ago

Seems like I am on the right path... -p is not the answer as one might think due to the help. I need to set --sourceDir then it works, trying this from init.d entry and will report back here.

vevmesteren commented 8 years ago

And that was it

here's the way that the service now looks to make the templating work properly

command="node"
nodeApp="/bin/www"
foreverApp="forever"
nodeAppDir="/myapp/"

and the start command now looks like so

$foreverApp start  --sourceDir=$nodeAppDir --pidFile $pidFile -l $logFile -a -d $nodeApp -c "$command" $nodeApp
vevmesteren commented 8 years ago

Reading through your main.js to see if I can create a patch for this