Skip to content

Instantly share code, notes, and snippets.

@seanhess
Created January 31, 2011 17:51
Show Gist options
  • Save seanhess/804464 to your computer and use it in GitHub Desktop.
Save seanhess/804464 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Starting with 'Hello World!'"
# WRITE FUGUE FILE
echo "var fugue = require('fugue')
var path = require('path')
var sys = require('sys')
var Port = 6001
var Host = '0.0.0.0'
var Workers = 1
var options = {}
options.started = function() {}
options.verbose = true
options.working_path = path.join(__dirname, '..')
options.log_file = '/tmp/apiweb.log'
options.master_pid_path = '/tmp/apiweb.pid'
options.worker_kill_timeout = 10000
fugue.start(require('./test'), Port, Host, Workers, options)
sys.puts('STARTED in production on ' + Port + ' with ' + Workers + ' workers')" > fugue.js
# WRITE EXPRESS FILE
echo "var express = require('express');
app = express.createServer();
app.get('/', function(req, res) {
res.send('Hello World!');
});
module.exports = app; " > test.js
# START FUGUE
node fugue.js &
sleep 1
curl http://localhost:6001
echo ""
sleep 1
# UPDATE THE FILE #
echo "Starting with 'Hello World - NEW VERSION!'"
echo "var express = require('express');
app = express.createServer();
app.get('/', function(req, res) {
res.send('Hello World - NEW VERSION!');
});
module.exports = app; " > test.js
kill -USR2 `cat /tmp/apiweb.pid`
sleep 1
echo "This never returns..."
curl http://localhost:6001 &
echo ""
echo "Sleeping for 5 seconds and exiting. Also, the worker process never dies after the SIGINT"
sleep 5
kill -SIGINT `cat /tmp/apiweb.pid`
# Was going to try this stuff below, but we'll need to resolve the fact that the
# last curl statement never returned first.
# echo "Sleeping for 30 seconds"
# sleep 30
# curl http://localhost:6001
# echo ""
# kill -SIGINT `cat /tmp/apiweb.pid`
## SAMPLE OUTPUT ##
# note that the empty reply from the server happens when I kill the worker by hand.
# woot:Downloads seanhess$ bash fugue.sh
# Starting with 'Hello World!'
# Hello World!
# Starting with 'Hello World - NEW VERSION!'
# This never returns...
#
# Sleeping for 5 seconds and exiting. Also, the worker process never dies after the SIGINT
# woot:Downloads seanhess$ curl: (52) Empty reply from server
## LOG FILE OUTPUT ##
# process 50797 said: Using master socket path: null
# process 50797 said: Starting new master...
# STARTED in production on 6001 with 1 workers
# process 50797 said: Spawning workers...
# process 50797 said: spawned.
# process 50797 said: master process PID: 50797
# process 50800 said: Using master socket path: /tmp/fugue_50797_master.sock
# process 50800 said: Worker here
# process 50800 said: worker trying to connect to master...
# STARTED in production on 6001 with 1 workers
# process 50800 said: worker connected to master
# process 50797 said: serving server socket file descriptor 1
# process 50800 said: worker listening
# process 50800 said: worker setup of signals is done
# process 50797 said: Got SIGUSR2, respawning self
# process 50805 said: Using master socket path: /tmp/fugue_50797_master.sock
# process 50805 said: Starting new master...
# process 50805 said: Trying to get socket back from original server...
# process 50805 said: connecting to /tmp/fugue_50797_master.sock
# process 50797 said: serving server socket file descriptor 1
# process 50805 said: Got response from server:HERE_YOU_GO
# STARTED in production on 6001 with 1 workers
# process 50805 said: Spawning workers...
# process 50805 said: spawned.
# process 50805 said: master process PID: 50805
# process 50806 said: Using master socket path: /tmp/fugue_50805_master.sock
# process 50806 said: Worker here
# process 50806 said: worker trying to connect to master...
# STARTED in production on 6001 with 1 workers
# process 50806 said: worker connected to master
# process 50805 said: serving server socket file descriptor 8
# process 50806 said: killing original master with pid 50797
# process 50797 said: killer here
# process 50806 said: worker listening
# process 50800 said: worker killer activated...
# process 50800 said: I have 0 server connections
# process 50800 said: Worker 1 exiting.
# process 50806 said: worker setup of signals is done
# process 50805 said: killer here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment