Document "user" directive in example unicorn conf
[unicorn.git] / t / t0012-reload-empty-config.sh
blob81e1fb33f9eedfbeb76c13b37b645efe5d1fd595
1 #!/bin/sh
2 . ./test-lib.sh
3 t_plan 9 "reloading unset config resets defaults"
5 t_begin "setup and start" && {
6 unicorn_setup
7 rtmpfiles unicorn_config_orig before_reload after_reload
8 cat $unicorn_config > $unicorn_config_orig
9 cat >> $unicorn_config <<EOF
10 logger Logger.new(STDOUT)
11 preload_app true
12 timeout 0x7fffffff
13 worker_processes 2
14 after_fork { |s,w| }
15 \$dump_cfg = lambda { |fp,srv|
16 defaults = Unicorn::Configurator::DEFAULTS
17 defaults.keys.map { |x| x.to_s }.sort.each do |key|
18 next if key =~ %r{\Astd(?:err|out)_path\z}
19 key = key.to_sym
20 def_value = defaults[key]
21 srv_value = srv.__send__(key)
22 fp << "#{key}|#{srv_value}|#{def_value}\\n"
23 end
25 before_fork { |s,w|
26 File.open("$before_reload", "a") { |fp| \$dump_cfg.call(fp, s) }
28 before_exec { |s| }
29 EOF
30 unicorn -D -c $unicorn_config env.ru
31 unicorn_wait_start
34 t_begin "ensure worker is started" && {
35 curl -sSf http://$listen/ > $tmp
38 t_begin "replace config file with original(-ish)" && {
39 grep -v ^pid < $unicorn_config_orig > $unicorn_config
40 cat >> $unicorn_config <<EOF
41 before_fork { |s,w|
42 File.open("$after_reload", "a") { |fp| \$dump_cfg.call(fp, s) }
44 EOF
47 t_begin "reload signal succeeds" && {
48 kill -HUP $unicorn_pid
49 while ! egrep '(done|error) reloading' $r_err >/dev/null
51 sleep 1
52 done
53 while ! grep reaped < $r_err >/dev/null
55 sleep 1
56 done
57 grep 'done reloading' $r_err >/dev/null
60 t_begin "ensure worker is started" && {
61 curl -sSf http://$listen/ > $tmp
64 t_begin "pid file no longer exists" && {
65 if test -f $pid
66 then
67 die "pid=$pid should not exist"
71 t_begin "killing succeeds" && {
72 kill $unicorn_pid
75 t_begin "check stderr" && {
76 check_stderr
79 t_begin "ensure reloading restored settings" && {
80 awk < $after_reload -F'|' '
81 $1 != "before_fork" && $2 != $3 { print $0; exit(1) }
85 t_done