gruntjs / grunt-contrib-connect

Start a static web server.
http://gruntjs.com
MIT License
714 stars 146 forks source link

grunt not staying alive #179

Closed rahul-desai3 closed 8 years ago

rahul-desai3 commented 9 years ago

I installed grunt-contrib-connect using npm and configured Gruntfile.js by adding grunt.loadNpmTasks('grunt-contrib-connect'); and the keepAlive flag in connect > options.

When I run it using grunt connect, my site works fine however, if I close the terminal, the site doesnt stay alive. In Chrome, I get ERR_CONNECTION_REFUSED if I try to access it.

Here is my complete Gruntfile.js: https://gist.github.com/rahul-desai3/a7a078181488e7b7bf1d

How do I fix this?

rahul-desai3 commented 9 years ago

This is what I see in my Windows terminal (cmd):

E:\cms\client>grunt connect
Running "connect:livereload" (connect) task
Waiting forever...
Started connect web server on http://localhost:9000
mmccollow commented 9 years ago

The problem is that your grunt tasks run as child processes of cmd.exe, so when you close your terminal, anything that's running within that context is killed. The simplest solution would just be to leave the terminal window open.

rahul-desai3 commented 9 years ago

How would I do this in the production environment? There I am using CentOS and cant keep the terminal window open.

shama commented 8 years ago

@rahul-desai3 I don't recommend using this in a production environment (or rather to serve up production assets). It's more for development.

There are a lot of options on npm for managing processes to keep a HTTP server open for production. Check out pm2 or forever.

I even made a video about how to run a node.js server forever: https://www.youtube.com/watch?v=P4mT5Tbx_KE