unicorn 5.0.1 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.manifest +1 -0
  3. data/.olddoc.yml +6 -4
  4. data/Documentation/unicorn.1.txt +2 -3
  5. data/Documentation/unicorn_rails.1.txt +3 -3
  6. data/FAQ +1 -1
  7. data/GIT-VERSION-FILE +1 -1
  8. data/GIT-VERSION-GEN +1 -1
  9. data/GNUmakefile +3 -3
  10. data/HACKING +1 -2
  11. data/ISSUES +21 -17
  12. data/KNOWN_ISSUES +2 -2
  13. data/LATEST +82 -28
  14. data/Links +3 -3
  15. data/NEWS +270 -0
  16. data/README +7 -19
  17. data/SIGNALS +1 -1
  18. data/Sandbox +6 -5
  19. data/TODO +0 -2
  20. data/TUNING +19 -1
  21. data/examples/big_app_gc.rb +1 -1
  22. data/examples/init.sh +36 -8
  23. data/examples/logrotate.conf +16 -1
  24. data/examples/nginx.conf +1 -1
  25. data/examples/unicorn.conf.minimal.rb +2 -2
  26. data/examples/unicorn.conf.rb +2 -2
  27. data/examples/unicorn@.service +7 -0
  28. data/ext/unicorn_http/common_field_optimization.h +2 -2
  29. data/ext/unicorn_http/ext_help.h +0 -20
  30. data/ext/unicorn_http/extconf.rb +1 -1
  31. data/ext/unicorn_http/global_variables.h +2 -2
  32. data/ext/unicorn_http/httpdate.c +2 -2
  33. data/ext/unicorn_http/unicorn_http.c +673 -358
  34. data/ext/unicorn_http/unicorn_http.rl +32 -16
  35. data/ext/unicorn_http/unicorn_http_common.rl +1 -1
  36. data/lib/unicorn/configurator.rb +71 -12
  37. data/lib/unicorn/http_request.rb +89 -9
  38. data/lib/unicorn/http_response.rb +5 -2
  39. data/lib/unicorn/http_server.rb +66 -22
  40. data/lib/unicorn/oob_gc.rb +4 -4
  41. data/lib/unicorn/socket_helper.rb +19 -4
  42. data/lib/unicorn/stream_input.rb +5 -4
  43. data/lib/unicorn/tee_input.rb +8 -10
  44. data/lib/unicorn/version.rb +1 -1
  45. data/lib/unicorn/worker.rb +17 -6
  46. data/lib/unicorn.rb +31 -20
  47. data/man/man1/unicorn.1 +54 -55
  48. data/man/man1/unicorn_rails.1 +47 -46
  49. data/t/t0011-active-unix-socket.sh +1 -1
  50. data/t/t0012-reload-empty-config.sh +2 -1
  51. data/t/test-lib.sh +2 -2
  52. data/test/exec/test_exec.rb +6 -5
  53. data/test/unit/test_ccc.rb +90 -0
  54. data/test/unit/test_http_parser.rb +31 -17
  55. data/test/unit/test_socket_helper.rb +8 -4
  56. data/test/unit/test_util.rb +2 -2
  57. data/unicorn.gemspec +15 -17
  58. metadata +6 -19
data/README CHANGED
@@ -13,7 +13,7 @@ both the the request and response in between unicorn and slow clients.
13
13
  {nginx}[http://nginx.org/] or {Rack}[http://rack.github.io/].
14
14
 
15
15
  * Compatible with Ruby 1.9.3 and later.
16
- unicorn 4.8.x will remain supported for Ruby 1.8 users.
16
+ unicorn 4.x remains supported for Ruby 1.8 users.
17
17
 
18
18
  * Process management: unicorn will reap and restart workers that
19
19
  die from broken apps. There is no need to manage multiple processes
@@ -27,9 +27,6 @@ both the the request and response in between unicorn and slow clients.
27
27
  all run within their own isolated address space and only serve one
28
28
  client at a time for maximum robustness.
29
29
 
30
- * Supports all Rack applications, along with pre-Rack versions of
31
- Ruby on Rails via a Rack wrapper.
32
-
33
30
  * Builtin reopening of all log files in your application via
34
31
  USR1 signal. This allows logrotate to rotate files atomically and
35
32
  quickly via rename instead of the racy and slow copytruncate method.
@@ -54,13 +51,11 @@ both the the request and response in between unicorn and slow clients.
54
51
 
55
52
  * Simple and easy Ruby DSL for configuration.
56
53
 
57
- * Decodes chunked transfers on-the-fly, thus allowing upload progress
58
- notification to be implemented as well as being able to tunnel
59
- arbitrary stream-based protocols over HTTP.
54
+ * Decodes chunked requests on-the-fly.
60
55
 
61
56
  == License
62
57
 
63
- unicorn is copyright 2009 by all contributors (see logs in git).
58
+ unicorn is copyright 2009-2016 by all contributors (see logs in git).
64
59
  It is based on Mongrel 1.1.5.
65
60
  Mongrel is copyright 2007 Zed A. Shaw and contributors.
66
61
 
@@ -68,7 +63,7 @@ unicorn is licensed under (your choice) of the GPLv2 or later
68
63
  (GPLv3+ preferred), or Ruby (1.8)-specific terms.
69
64
  See the included LICENSE file for details.
70
65
 
71
- unicorn is 100% Free Software.
66
+ unicorn is 100% Free Software (including all development tools used).
72
67
 
73
68
  == Install
74
69
 
@@ -85,10 +80,9 @@ You can get the latest source via git from the following locations
85
80
  git://bogomips.org/unicorn.git
86
81
  git://repo.or.cz/unicorn.git (mirror)
87
82
 
88
- You may browse the code from the web and download the latest snapshot
89
- tarballs here:
83
+ You may browse the code from the web:
90
84
 
91
- * http://bogomips.org/unicorn.git (cgit)
85
+ * https://bogomips.org/unicorn.git
92
86
  * http://repo.or.cz/w/unicorn.git (gitweb)
93
87
 
94
88
  See the HACKING guide on how to contribute and build prerelease gems
@@ -102,12 +96,6 @@ In APP_ROOT, run:
102
96
 
103
97
  unicorn
104
98
 
105
- === Ancient Rails 1.2 - 2.x versions
106
-
107
- In RAILS_ROOT, run:
108
-
109
- unicorn_rails
110
-
111
99
  unicorn will bind to all interfaces on TCP port 8080 by default.
112
100
  You may use the +--listen/-l+ switch to bind to a different
113
101
  address:port or a UNIX socket.
@@ -140,7 +128,7 @@ All feedback (bug reports, user/development dicussion, patches, pull
140
128
  requests) go to the mailing list/newsgroup. See the ISSUES document for
141
129
  information on the {mailing list}[mailto:unicorn-public@bogomips.org].
142
130
 
143
- The mailing list is archived at http://bogomips.org/unicorn-public/
131
+ The mailing list is archived at https://bogomips.org/unicorn-public/
144
132
  Read-only NNTP access is available at:
145
133
  nntp://news.public-inbox.org/inbox.comp.lang.ruby.unicorn and
146
134
  nntp://news.gmane.org/gmane.comp.lang.ruby.unicorn.general
data/SIGNALS CHANGED
@@ -8,7 +8,7 @@ should be possible to easily share process management scripts between
8
8
  Unicorn and nginx.
9
9
 
10
10
  One example init script is distributed with unicorn:
11
- http://unicorn.bogomips.org/examples/init.sh
11
+ https://bogomips.org/unicorn/examples/init.sh
12
12
 
13
13
  === Master Process
14
14
 
data/Sandbox CHANGED
@@ -34,7 +34,7 @@ is the primary issue with sandboxing tools such as Bundler and Isolate.
34
34
  If you're bundling unicorn, use "bundle exec unicorn" (or "bundle exec
35
35
  unicorn_rails") to start unicorn with the correct environment variables
36
36
 
37
- ref: http://mid.gmane.org/9ECF07C4-5216-47BE-961D-AFC0F0C82060@internetfamo.us
37
+ ref: https://bogomips.org/unicorn-public/9ECF07C4-5216-47BE-961D-AFC0F0C82060@internetfamo.us/
38
38
 
39
39
  Otherwise (if you choose to not sandbox your unicorn installation), we
40
40
  expect the tips for Isolate (below) apply, too.
@@ -43,7 +43,8 @@ expect the tips for Isolate (below) apply, too.
43
43
 
44
44
  This is no longer be an issue as of bundler 0.9.17
45
45
 
46
- ref: http://mid.gmane.org/8FC34B23-5994-41CC-B5AF-7198EF06909E@tramchase.com
46
+ ref:
47
+ https://bogomips.org/unicorn-public/8FC34B23-5994-41CC-B5AF-7198EF06909E@tramchase.com/
47
48
 
48
49
  === BUNDLE_GEMFILE for Capistrano users
49
50
 
@@ -63,9 +64,9 @@ before_exec hook as illustrated by https://gist.github.com/534668
63
64
  === Ruby 2.0.0 close-on-exec and SIGUSR2 incompatibility
64
65
 
65
66
  Ruby 2.0.0 enforces FD_CLOEXEC on file descriptors by default. unicorn
66
- has been prepared for this behavior since unicorn 4.1.0, but we forgot
67
- to remind the Bundler developers. This issue is being tracked here:
68
- https://github.com/bundler/bundler/issues/2628
67
+ has been prepared for this behavior since unicorn 4.1.0, and bundler
68
+ needs the "--keep-file-descriptors" option for "bundle exec":
69
+ http://bundler.io/man/bundle-exec.1.html
69
70
 
70
71
  == Isolate
71
72
 
data/TODO CHANGED
@@ -1,5 +1,3 @@
1
1
  * Documentation improvements
2
2
 
3
3
  * improve test suite
4
-
5
- * Rack 2.x support (when Rack 2.x exists)
data/TUNING CHANGED
@@ -72,10 +72,28 @@ See Unicorn::Configurator for details on the config file format.
72
72
  have them unbuffered (File#sync = true) or they are
73
73
  record(line)-buffered in userspace before any writes.
74
74
 
75
- == Kernel Parameters (Linux sysctl)
75
+ == Kernel Parameters (Linux sysctl and sysfs)
76
76
 
77
77
  WARNING: Do not change system parameters unless you know what you're doing!
78
78
 
79
+ * Transparent hugepages (THP) improves performance in many cases,
80
+ but can also increase memory use when relying on a
81
+ copy-on-write(CoW)-friendly GC (Ruby 2.0+) with "preload_app true".
82
+ CoW operates at the page level, so writing to a huge page would
83
+ trigger a 2 MB copy (x86-64), as opposed to a 4 KB copy on a
84
+ regular (non-huge) page.
85
+
86
+ Consider only allowing THP to be used when it is requested via the
87
+ madvise(2) syscall:
88
+
89
+ echo madvise >/sys/kernel/mm/transparent_hugepage/enabled
90
+
91
+ Or disabling it system-wide, via "never".
92
+
93
+ n.b. "page" in this context only applies to the OS kernel,
94
+ Ruby GC implementations also use this term for the same concept
95
+ in a way that is agnostic to the OS.
96
+
79
97
  * net.core.rmem_max and net.core.wmem_max can increase the allowed
80
98
  size of :rcvbuf and :sndbuf respectively. This is mostly only useful
81
99
  for UNIX domain sockets which do not have auto-tuning buffer sizes.
@@ -1,2 +1,2 @@
1
- # see {Unicorn::OobGC}[http://unicorn.bogomips.org/Unicorn/OobGC.html]
1
+ # see {Unicorn::OobGC}[https://bogomips.org/unicorn/Unicorn/OobGC.html]
2
2
  # Unicorn::OobGC was broken in Unicorn v3.3.1 - v3.6.1 and fixed in v3.6.2
data/examples/init.sh CHANGED
@@ -1,7 +1,16 @@
1
1
  #!/bin/sh
2
2
  set -e
3
+ ### BEGIN INIT INFO
4
+ # Provides: unicorn
5
+ # Required-Start: $local_fs $network
6
+ # Required-Stop: $local_fs $network
7
+ # Default-Start: 2 3 4 5
8
+ # Default-Stop: 0 1 6
9
+ # Short-Description: Start/stop unicorn Rack app server
10
+ ### END INIT INFO
11
+
3
12
  # Example init script, this can be used with nginx, too,
4
- # since nginx and unicorn accept the same signals
13
+ # since nginx and unicorn accept the same signals.
5
14
 
6
15
  # Feel free to change any of the following variables for your app:
7
16
  TIMEOUT=${TIMEOUT-60}
@@ -9,21 +18,22 @@ APP_ROOT=/home/x/my_app/current
9
18
  PID=$APP_ROOT/tmp/pids/unicorn.pid
10
19
  CMD="/usr/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb"
11
20
  INIT_CONF=$APP_ROOT/config/init.conf
21
+ UPGRADE_DELAY=${UPGRADE_DELAY-2}
12
22
  action="$1"
13
23
  set -u
14
24
 
15
25
  test -f "$INIT_CONF" && . $INIT_CONF
16
26
 
17
- old_pid="$PID.oldbin"
27
+ OLD="$PID.oldbin"
18
28
 
19
29
  cd $APP_ROOT || exit 1
20
30
 
21
31
  sig () {
22
- test -s "$PID" && kill -$1 `cat $PID`
32
+ test -s "$PID" && kill -$1 $(cat $PID)
23
33
  }
24
34
 
25
35
  oldsig () {
26
- test -s $old_pid && kill -$1 `cat $old_pid`
36
+ test -s "$OLD" && kill -$1 $(cat $OLD)
27
37
  }
28
38
 
29
39
  case $action in
@@ -45,18 +55,36 @@ restart|reload)
45
55
  $CMD
46
56
  ;;
47
57
  upgrade)
48
- if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
58
+ if oldsig 0
59
+ then
60
+ echo >&2 "Old upgraded process still running with $OLD"
61
+ exit 1
62
+ fi
63
+
64
+ cur_pid=
65
+ if test -s "$PID"
66
+ then
67
+ cur_pid=$(cat $PID)
68
+ fi
69
+
70
+ if test -n "$cur_pid" &&
71
+ kill -USR2 "$cur_pid" &&
72
+ sleep $UPGRADE_DELAY &&
73
+ new_pid=$(cat $PID) &&
74
+ test x"$new_pid" != x"$cur_pid" &&
75
+ kill -0 "$new_pid" &&
76
+ kill -QUIT "$cur_pid"
49
77
  then
50
78
  n=$TIMEOUT
51
- while test -s $old_pid && test $n -ge 0
79
+ while kill -0 "$cur_pid" 2>/dev/null && test $n -ge 0
52
80
  do
53
81
  printf '.' && sleep 1 && n=$(( $n - 1 ))
54
82
  done
55
83
  echo
56
84
 
57
- if test $n -lt 0 && test -s $old_pid
85
+ if test $n -lt 0 && kill -0 "$cur_pid" 2>/dev/null
58
86
  then
59
- echo >&2 "$old_pid still exists after $TIMEOUT seconds"
87
+ echo >&2 "$cur_pid still running after $TIMEOUT seconds"
60
88
  exit 1
61
89
  fi
62
90
  exit 0
@@ -3,6 +3,9 @@
3
3
  #
4
4
  # See the logrotate(8) manpage for more information:
5
5
  # http://linux.die.net/man/8/logrotate
6
+ #
7
+ # public logrotate-related discussion in our archives:
8
+ # https://bogomips.org/unicorn-public/?q=logrotate
6
9
 
7
10
  # Modify the following glob to match the logfiles your app writes to:
8
11
  /var/log/unicorn_app/*.log {
@@ -22,7 +25,19 @@
22
25
  # config. Unicorn supports the USR1 signal and we send it
23
26
  # as our "lastaction" action:
24
27
  lastaction
25
- # assuming your pid file is in /var/run/unicorn_app/pid
28
+ # For systemd users, assuming you use two services
29
+ # (as recommended) to allow zero-downtime upgrades.
30
+ # Only one service needs to be started, but signaling
31
+ # both here is harmless as long as they're both enabled
32
+ systemctl kill -s SIGUSR1 unicorn@1.service
33
+ systemctl kill -s SIGUSR1 unicorn@2.service
34
+
35
+ # Examples for other process management systems appreciated
36
+ # Mail us at unicorn-public@bogomips.org
37
+ # (see above for archives)
38
+
39
+ # If you use a pid file and assuming your pid file
40
+ # is in /var/run/unicorn_app/pid
26
41
  pid=/var/run/unicorn_app/pid
27
42
  test -s $pid && kill -USR1 "$(cat $pid)"
28
43
  endscript
data/examples/nginx.conf CHANGED
@@ -112,7 +112,7 @@ http {
112
112
  # try_files directive appeared in in nginx 0.7.27 and has stabilized
113
113
  # over time. Older versions of nginx (e.g. 0.6.x) requires
114
114
  # "if (!-f $request_filename)" which was less efficient:
115
- # http://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127
115
+ # https://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127
116
116
  try_files $uri/index.html $uri.html $uri @app;
117
117
 
118
118
  location @app {
@@ -1,9 +1,9 @@
1
1
  # Minimal sample configuration file for Unicorn (not Rack) when used
2
2
  # with daemonization (unicorn -D) started in your working directory.
3
3
  #
4
- # See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
4
+ # See https://bogomips.org/unicorn/Unicorn/Configurator.html for complete
5
5
  # documentation.
6
- # See also http://unicorn.bogomips.org/examples/unicorn.conf.rb for
6
+ # See also https://bogomips.org/unicorn/examples/unicorn.conf.rb for
7
7
  # a more verbose configuration using more features.
8
8
 
9
9
  listen 2007 # by default Unicorn listens on port 8080
@@ -2,10 +2,10 @@
2
2
  #
3
3
  # This configuration file documents many features of Unicorn
4
4
  # that may not be needed for some applications. See
5
- # http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
5
+ # https://bogomips.org/unicorn/examples/unicorn.conf.minimal.rb
6
6
  # for a much simpler configuration file.
7
7
  #
8
- # See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
8
+ # See https://bogomips.org/unicorn/Unicorn/Configurator.html for complete
9
9
  # documentation.
10
10
 
11
11
  # Use at least one worker per core if you're on a dedicated server,
@@ -11,6 +11,8 @@ Wants = unicorn.socket
11
11
  After = unicorn.socket
12
12
 
13
13
  [Service]
14
+ # bundler users must use the "--keep-file-descriptors" switch, here:
15
+ # ExecStart = bundle exec --keep-file-descriptors unicorn -c ...
14
16
  ExecStart = /usr/bin/unicorn -c /path/to/unicorn.conf.rb /path/to/config.ru
15
17
  Sockets = unicorn.socket
16
18
  KillSignal = SIGQUIT
@@ -22,5 +24,10 @@ ExecReload = /bin/kill -HUP $MAINPID
22
24
  # adding a few seconds for scheduling differences:
23
25
  TimeoutStopSec = 62
24
26
 
27
+ # Only kill the master process, it may be harmful to signal
28
+ # workers via default "control-group" setting since some
29
+ # Ruby extensions and applications misbehave on interrupts
30
+ KillMode = process
31
+
25
32
  [Install]
26
33
  WantedBy = multi-user.target
@@ -60,7 +60,7 @@ static struct common_field common_http_fields[] = {
60
60
  #define HTTP_PREFIX_LEN (sizeof(HTTP_PREFIX) - 1)
61
61
 
62
62
  /* this function is not performance-critical, called only at load time */
63
- static void init_common_fields(void)
63
+ static void init_common_fields(VALUE mark_ary)
64
64
  {
65
65
  int i;
66
66
  struct common_field *cf = common_http_fields;
@@ -77,7 +77,7 @@ static void init_common_fields(void)
77
77
  cf->value = rb_str_new(tmp, HTTP_PREFIX_LEN + cf->len);
78
78
  }
79
79
  cf->value = rb_obj_freeze(cf->value);
80
- rb_global_variable(&cf->value);
80
+ rb_ary_push(mark_ary, cf->value);
81
81
  }
82
82
  }
83
83
 
@@ -1,26 +1,6 @@
1
1
  #ifndef ext_help_h
2
2
  #define ext_help_h
3
3
 
4
- #ifndef RSTRING_PTR
5
- #define RSTRING_PTR(s) (RSTRING(s)->ptr)
6
- #endif /* !defined(RSTRING_PTR) */
7
- #ifndef RSTRING_LEN
8
- #define RSTRING_LEN(s) (RSTRING(s)->len)
9
- #endif /* !defined(RSTRING_LEN) */
10
-
11
- #ifndef HAVE_RB_STR_SET_LEN
12
- # ifdef RUBINIUS
13
- # error we should never get here with current Rubinius (1.x)
14
- # endif
15
- /* this is taken from Ruby 1.8.7, 1.8.6 may not have it */
16
- static void rb_18_str_set_len(VALUE str, long len)
17
- {
18
- RSTRING(str)->len = len;
19
- RSTRING(str)->ptr[len] = '\0';
20
- }
21
- # define rb_str_set_len(str,len) rb_18_str_set_len(str,len)
22
- #endif /* !defined(HAVE_RB_STR_SET_LEN) */
23
-
24
4
  /* not all Ruby implementations support frozen objects (Rubinius does not) */
25
5
  #if defined(OBJ_FROZEN)
26
6
  # define assert_frozen(f) assert(OBJ_FROZEN(f) && "unfrozen object")
@@ -4,7 +4,7 @@ require 'mkmf'
4
4
  have_macro("SIZEOF_OFF_T", "ruby.h") or check_sizeof("off_t", "sys/types.h")
5
5
  have_macro("SIZEOF_SIZE_T", "ruby.h") or check_sizeof("size_t", "sys/types.h")
6
6
  have_macro("SIZEOF_LONG", "ruby.h") or check_sizeof("long", "sys/types.h")
7
- have_func("rb_str_set_len", "ruby.h")
7
+ have_func("rb_str_set_len", "ruby.h") or abort 'Ruby 1.9.3+ required'
8
8
  have_func("rb_hash_clear", "ruby.h") # Ruby 2.0+
9
9
  have_func("gmtime_r", "time.h")
10
10
 
@@ -56,7 +56,7 @@ NORETURN(static void parser_raise(VALUE klass, const char *));
56
56
  /** Defines global strings in the init method. */
57
57
  #define DEF_GLOBAL(N, val) do { \
58
58
  g_##N = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \
59
- rb_global_variable(&g_##N); \
59
+ rb_ary_push(mark_ary, g_##N); \
60
60
  } while (0)
61
61
 
62
62
  /* Defines the maximum allowed lengths for various input elements.*/
@@ -67,7 +67,7 @@ DEF_MAX_LENGTH(FRAGMENT, 1024); /* Don't know if this length is specified somewh
67
67
  DEF_MAX_LENGTH(REQUEST_PATH, 4096); /* common PATH_MAX on modern systems */
68
68
  DEF_MAX_LENGTH(QUERY_STRING, (1024 * 10));
69
69
 
70
- static void init_globals(void)
70
+ static void init_globals(VALUE mark_ary)
71
71
  {
72
72
  DEF_GLOBAL(rack_url_scheme, "rack.url_scheme");
73
73
  DEF_GLOBAL(request_method, "REQUEST_METHOD");
@@ -64,13 +64,13 @@ static VALUE httpdate(VALUE self)
64
64
  return buf;
65
65
  }
66
66
 
67
- void init_unicorn_httpdate(void)
67
+ void init_unicorn_httpdate(VALUE mark_ary)
68
68
  {
69
69
  VALUE mod = rb_define_module("Unicorn");
70
70
  mod = rb_define_module_under(mod, "HttpResponse");
71
71
 
72
72
  buf = rb_str_new(0, buf_capa - 1);
73
- rb_global_variable(&buf);
73
+ rb_ary_push(mark_ary, buf);
74
74
  buf_ptr = RSTRING_PTR(buf);
75
75
  httpdate(Qnil);
76
76