Merge remote-tracking branch 'origin/website-move'
[unicorn.git] / t / t0003-working_directory.sh
blob79988d8bbf5c37f9b627b1877111a4f70a63c1e4
1 #!/bin/sh
2 . ./test-lib.sh
4 t_plan 4 "config.ru inside alt working_directory"
6 t_begin "setup and start" && {
7 unicorn_setup
8 rtmpfiles unicorn_config_tmp
9 rm -rf $t_pfx.app
10 mkdir $t_pfx.app
12 cat > $t_pfx.app/config.ru <<EOF
13 #\--daemonize --host $host --port $port
14 use Rack::ContentLength
15 use Rack::ContentType, "text/plain"
16 run lambda { |env| [ 200, {}, [ "#{\$master_ppid}\\n" ] ] }
17 EOF
18 # we have --host/--port in config.ru instead
19 grep -v ^listen $unicorn_config > $unicorn_config_tmp
21 # the whole point of this exercise
22 echo "working_directory '$t_pfx.app'" >> $unicorn_config_tmp
24 # allows ppid to be 1 in before_fork
25 echo "preload_app true" >> $unicorn_config_tmp
26 cat >> $unicorn_config_tmp <<\EOF
27 before_fork do |server,worker|
28 $master_ppid = Process.ppid # should be zero to detect daemonization
29 end
30 EOF
32 mv $unicorn_config_tmp $unicorn_config
34 # rely on --daemonize switch, no & or -D
35 unicorn -c $unicorn_config
36 unicorn_wait_start
39 t_begin "hit with curl" && {
40 body=$(curl -sSf http://$listen/)
43 t_begin "killing succeeds" && {
44 kill $unicorn_pid
47 t_begin "response body ppid == 1 (daemonized)" && {
48 test "$body" -eq 1
51 t_done