unicorn 1.1.5
[unicorn.git] / t / t0003-working_directory.sh
blob53345ae9cb7cf2feac135ddf25877c0dab06e3f4
1 #!/bin/sh
2 if test -n "$RBX_SKIP"
3 then
4 echo "$0 is broken under Rubinius for now"
5 exit 0
6 fi
7 . ./test-lib.sh
9 t_plan 4 "config.ru inside alt working_directory"
11 t_begin "setup and start" && {
12 unicorn_setup
13 rtmpfiles unicorn_config_tmp
14 rm -rf $t_pfx.app
15 mkdir $t_pfx.app
17 cat > $t_pfx.app/config.ru <<EOF
18 #\--daemonize --host $host --port $port
19 use Rack::ContentLength
20 use Rack::ContentType, "text/plain"
21 run lambda { |env| [ 200, {}, [ "#{\$master_ppid}\\n" ] ] }
22 EOF
23 # we have --host/--port in config.ru instead
24 grep -v ^listen $unicorn_config > $unicorn_config_tmp
26 # the whole point of this exercise
27 echo "working_directory '$t_pfx.app'" >> $unicorn_config_tmp
29 # allows ppid to be 1 in before_fork
30 echo "preload_app true" >> $unicorn_config_tmp
31 cat >> $unicorn_config_tmp <<\EOF
32 before_fork do |server,worker|
33 $master_ppid = Process.ppid # should be zero to detect daemonization
34 end
35 EOF
37 mv $unicorn_config_tmp $unicorn_config
39 # rely on --daemonize switch, no & or -D
40 unicorn -c $unicorn_config
41 unicorn_wait_start
44 t_begin "hit with curl" && {
45 body=$(curl -sSf http://$listen/)
48 t_begin "killing succeeds" && {
49 kill $unicorn_pid
52 t_begin "response body ppid == 1 (daemonized)" && {
53 test "$body" -eq 1
56 t_done