0
votes

I am using an amazon ec2 instance with ubuntu to host my node.js application, i already made all the configurations, and is working good when i type:

nodemon ./bin/www

./bin/www is the file that creates the server.

Now, i am trying to setup the upstart, and i follow a tutorial, this is my configuration file:

path:

/etc/init/photogrid.conf:

inside:

description "Photogrid"

start on started mountall
stop on shutdown

respawn
respawn limit 99 5

env NODE_ENV=production

exec node /home/ubuntu/photogrid/bin/www >> /var/log/photogrid.log 2>&1

But when i try to access the site, is showing:

Cannot GET /

I follow a tutorial, and the only difference between my configuration file is this part:

Original:

exec node /home/ubuntu/photogrid/app.js >> /var/log/photogrid.log 2>&1

My one:

exec node /home/ubuntu/photogrid/bin/www >> /var/log/photogrid.log 2>&1

Start with upstart:

enter image description here

Start with nodemon bin/www:

enter image description here

In my logs i see the following when i try access the home '/':

^[[0mGET / ^[[33m404 ^[[0m12.036 ms - 13^[[0m
2
Upstart is correctly starting the process and express is clearly running and serving HTTP as that is the default express 404 Not Found message. Did you actually define your routes including a home page something like app.get("/", ...? - Peter Lyons
of course @PeterLyons, if i start with nodemon ./bin/www will work fine, the page will render normally. - user4520762
see my update question @PeterLyons - user4520762
You need to post your express code. Something is weird there but I'm not going to remotely blind debug it for you. Your "cannot find module /chdir" sounds like you have some bizarre javascript in your app. - Peter Lyons

2 Answers

1
votes

It seems that you need to switch to correct directory before launching exec. Maybe this will resolve your error:

description "Photogrid"

start on filesystem and started networking
stop on shutdown

respawn
respawn limit 99 5

env NODE_ENV=production

script
  export HOME="/home/ubuntu/photogrid"
  cd $HOME
  exec node /home/ubuntu/photogrid/bin/www >> /var/log/photogrid.log 2>&1
end script
0
votes

Try adding chdir /home/ubuntu/photogrid to your upstart config. Also, interactively in a terminal try: NODE_ENV=production nodemon ./bin/www. Perhaps you are using app.configure where you shouldn't be?