Created
December 25, 2013 12:08
-
-
Save aral/8122688 to your computer and use it in GitHub Desktop.
Using nginx for dev is much faster than grunt-contrib-connect (especially with a livereload workflow) but grunt-nginx doesn’t automatically shut down the server when exiting (e.g., on CTRL-C when watching, or if there is an exception). This little snippet will detect and shut down the server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# e.g. set up nginx task | |
module.exports = (grunt) -> | |
grunt.initConfig | |
nginx: | |
options: | |
config: '/usr/local/etc/nginx/nginx.conf' | |
# … | |
# Make sure we shut down the nginx server in case it’s running. | |
exec = require('child_process').exec | |
cleanup = -> | |
console.log('') | |
console.log('=============================================') | |
console.log('Exiting gracefully. Shutting down the server…') | |
console.log('=============================================') | |
exec 'nginx -s stop', (error, stdout, stderr) -> | |
if error | |
console.log 'Couldn’t stop server: ' + error | |
console.log stdout | |
console.log stderr | |
process.exit() | |
process.on 'SIGINT', cleanup | |
process.on 'uncaughtException', cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment