giga-smart-mod 0.0.1

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 (55) hide show
  1. checksums.yaml +7 -0
  2. data/giga-smart-mod.gemspec +12 -0
  3. data/thin-2.0.1/CHANGELOG +422 -0
  4. data/thin-2.0.1/README.md +88 -0
  5. data/thin-2.0.1/Rakefile +22 -0
  6. data/thin-2.0.1/bin/thin +6 -0
  7. data/thin-2.0.1/example/adapter.rb +32 -0
  8. data/thin-2.0.1/example/async_app.ru +126 -0
  9. data/thin-2.0.1/example/async_chat.ru +247 -0
  10. data/thin-2.0.1/example/async_tailer.ru +100 -0
  11. data/thin-2.0.1/example/config.ru +22 -0
  12. data/thin-2.0.1/example/monit_sockets +20 -0
  13. data/thin-2.0.1/example/monit_unixsock +20 -0
  14. data/thin-2.0.1/example/myapp.rb +1 -0
  15. data/thin-2.0.1/example/ramaze.ru +12 -0
  16. data/thin-2.0.1/example/thin.god +80 -0
  17. data/thin-2.0.1/example/thin_solaris_smf.erb +36 -0
  18. data/thin-2.0.1/example/thin_solaris_smf.readme.txt +150 -0
  19. data/thin-2.0.1/example/vlad.rake +72 -0
  20. data/thin-2.0.1/ext/thin_parser/common.rl +59 -0
  21. data/thin-2.0.1/ext/thin_parser/ext_help.h +14 -0
  22. data/thin-2.0.1/ext/thin_parser/extconf.rb +6 -0
  23. data/thin-2.0.1/ext/thin_parser/parser.c +1447 -0
  24. data/thin-2.0.1/ext/thin_parser/parser.h +49 -0
  25. data/thin-2.0.1/ext/thin_parser/parser.rl +152 -0
  26. data/thin-2.0.1/ext/thin_parser/thin.c +435 -0
  27. data/thin-2.0.1/lib/rack/adapter/loader.rb +82 -0
  28. data/thin-2.0.1/lib/rack/adapter/rails.rb +172 -0
  29. data/thin-2.0.1/lib/rack/handler/thin.rb +13 -0
  30. data/thin-2.0.1/lib/rackup/handler/thin.rb +13 -0
  31. data/thin-2.0.1/lib/thin/backends/base.rb +169 -0
  32. data/thin-2.0.1/lib/thin/backends/swiftiply_client.rb +66 -0
  33. data/thin-2.0.1/lib/thin/backends/tcp_server.rb +34 -0
  34. data/thin-2.0.1/lib/thin/backends/unix_server.rb +56 -0
  35. data/thin-2.0.1/lib/thin/command.rb +53 -0
  36. data/thin-2.0.1/lib/thin/connection.rb +219 -0
  37. data/thin-2.0.1/lib/thin/controllers/cluster.rb +178 -0
  38. data/thin-2.0.1/lib/thin/controllers/controller.rb +189 -0
  39. data/thin-2.0.1/lib/thin/controllers/service.rb +76 -0
  40. data/thin-2.0.1/lib/thin/controllers/service.sh.erb +39 -0
  41. data/thin-2.0.1/lib/thin/daemonizing.rb +199 -0
  42. data/thin-2.0.1/lib/thin/env.rb +35 -0
  43. data/thin-2.0.1/lib/thin/headers.rb +47 -0
  44. data/thin-2.0.1/lib/thin/logging.rb +174 -0
  45. data/thin-2.0.1/lib/thin/rackup/handler.rb +33 -0
  46. data/thin-2.0.1/lib/thin/request.rb +159 -0
  47. data/thin-2.0.1/lib/thin/response.rb +144 -0
  48. data/thin-2.0.1/lib/thin/runner.rb +238 -0
  49. data/thin-2.0.1/lib/thin/server.rb +290 -0
  50. data/thin-2.0.1/lib/thin/stats.html.erb +216 -0
  51. data/thin-2.0.1/lib/thin/stats.rb +52 -0
  52. data/thin-2.0.1/lib/thin/statuses.rb +48 -0
  53. data/thin-2.0.1/lib/thin/version.rb +19 -0
  54. data/thin-2.0.1/lib/thin.rb +45 -0
  55. metadata +94 -0
@@ -0,0 +1,150 @@
1
+ Using Thin with Solaris' SMF Monitoring Framework
2
+ - - - - - - - - - - - - - - - - - - - - - - - - -
3
+
4
+ Solaris uses the Service Management Framework (SMF) at the OS level to manage, monitor, and restart long running processes. This replaces init scripts, and tools like monit and god.
5
+
6
+ The sample XML file (thin_solaris_smf.erb) is an example SMF manifest which I use on a Joyent accelerator which runs on OpenSolaris.
7
+
8
+ This setup will:
9
+
10
+ - ensure the right dependencies are loaded
11
+ - start n instances of Thin, and monitor each individually. If any single one dies it will be restarted instantly (test it by killing a single thin instance and it will be back alive before you can type 'ps -ef').
12
+
13
+ This is better than using clustering since if you start the cluster with SMF it will only notice a problem and restart individual Thin's if ALL of them are dead, at which point it will restart the whole cluster. This approach makes sure that all of your Thins start together and are monitored and managed independant of each other. This problem likely exists if you are using god or monit to monitor only the start of the master cluster, and don't then monitor the individual processes started.
14
+
15
+ This example is in .erb format instead of plain XML since I dynamically generate this file as part of a Capistrano deployment. In my deploy.rb file I define the variables found in this erb. Of course you don't need to use this with Capistrano. Just replace the few ERB variables from the xml file, change its extension, and load that directly in Solaris if you prefer.
16
+
17
+ Here are some examples for usage to get you started with Capistrano, and Thin:
18
+
19
+ FILE : config/deploy.rb
20
+ --
21
+
22
+ require 'config/accelerator/accelerator_tasks'
23
+
24
+ set :application, "yourapp"
25
+ set :svcadm_bin, "/usr/sbin/svcadm"
26
+ set :svccfg_bin, "/usr/sbin/svccfg"
27
+ set :svcs_bin, "/usr/bin/svcs"
28
+
29
+ # gets the list of remote service SMF names that we need to start
30
+ # like (depending on thin_max_instances settings):
31
+ # svc:/network/thin/yourapp-production:i_0
32
+ # svc:/network/thin/yourapp-production:i_1
33
+ # svc:/network/thin/yourapp-production:i_2
34
+ set :service_list, "`svcs -H -o FMRI svc:network/thin/#{application}-production`"
35
+
36
+ # how many Thin instances should be setup to run?
37
+ # this affects the generated thin smf file, and the nginx vhost conf
38
+ # need to re-run setup for thin smf and nginx vhost conf when changed
39
+ set :thin_max_instances, 3
40
+
41
+ # OVERRIDE STANDARD TASKS
42
+ desc "Restart the entire application"
43
+ deploy.task :restart do
44
+ accelerator.thin.restart
45
+ accelerator.nginx.restart
46
+ end
47
+
48
+ desc "Start the entire application"
49
+ deploy.task :start do
50
+ accelerator.thin.restart
51
+ accelerator.nginx.restart
52
+ end
53
+
54
+ desc "Stop the entire application"
55
+ deploy.task :stop do
56
+ accelerator.thin.disable
57
+ accelerator.nginx.disable
58
+ end
59
+
60
+
61
+ FILE : config/accelerator/accelerator_tasks.rb
62
+ --
63
+
64
+ desc "Create and deploy Thin SMF config"
65
+ task :create_thin_smf, :roles => :app do
66
+ service_name = application
67
+ working_directory = current_path
68
+ template = File.read("config/accelerator/thin_solaris_smf.erb")
69
+ buffer = ERB.new(template).result(binding)
70
+ put buffer, "#{shared_path}/#{application}-thin-smf.xml"
71
+ sudo "#{svccfg_bin} import #{shared_path}/#{application}-thin-smf.xml"
72
+ end
73
+
74
+ desc "Delete Thin SMF config"
75
+ task :delete_thin_smf, :roles => :app do
76
+ accelerator.thin.disable
77
+ sudo "#{svccfg_bin} delete /network/thin/#{application}-production"
78
+ end
79
+
80
+ desc "Show all SMF services"
81
+ task :svcs do
82
+ run "#{svcs_bin} -a" do |ch, st, data|
83
+ puts data
84
+ end
85
+ end
86
+
87
+ desc "Shows all non-functional SMF services"
88
+ task :svcs_broken do
89
+ run "#{svcs_bin} -vx" do |ch, st, data|
90
+ puts data
91
+ end
92
+ end
93
+
94
+
95
+ namespace :thin do
96
+
97
+ desc "Disable all Thin servers"
98
+ task :disable, :roles => :app do
99
+ # temporarily disable, until next reboot (-t)
100
+ sudo "#{svcadm_bin} disable -t #{service_list}"
101
+ end
102
+
103
+ desc "Enable all Thin servers"
104
+ task :enable, :roles => :app do
105
+ # start the app with all recursive dependencies
106
+ sudo "#{svcadm_bin} enable -r #{service_list}"
107
+ end
108
+
109
+ desc "Restart all Thin servers"
110
+ task :restart, :roles => :app do
111
+ # svcadm restart doesn't seem to work right, so we'll brute force it
112
+ disable
113
+ enable
114
+ end
115
+
116
+ end # namespace thin
117
+
118
+
119
+ FILE : config/thin.yml
120
+ --
121
+
122
+ ---
123
+ pid: tmp/pids/thin.pid
124
+ socket: /tmp/thin.sock
125
+ log: log/thin.log
126
+ max_conns: 1024
127
+ timeout: 30
128
+ chdir: /your/app/dir/rails/root
129
+ environment: production
130
+ max_persistent_conns: 512
131
+ daemonize: true
132
+ servers: 3
133
+
134
+
135
+ FILE : config/accelerator/thin_solaris_smf.erb
136
+ --
137
+ This is of course an example. It works for me, but YMMV
138
+
139
+ You may need to change this line to match your environment and config:
140
+ exec='/opt/csw/bin/thin -C config/thin.yml --only <%= instance.to_s %> start'
141
+
142
+
143
+ CONTRIBUTE:
144
+
145
+ If you see problems or enhancements for this approach please send me an email at glenn [at] rempe dot us. Sadly, I won't be able to provide support for this example as time and my limited Solaris admin skills won't allow.
146
+
147
+ Cheers,
148
+
149
+ Glenn Rempe
150
+ 2008/03/20
@@ -0,0 +1,72 @@
1
+ # $GEM_HOME/gems/vlad-1.2.0/lib/vlad/thin.rb
2
+ # Thin tasks for Vlad the Deployer
3
+ # By cnantais
4
+ require 'vlad'
5
+
6
+ namespace :vlad do
7
+ ##
8
+ # Thin app server
9
+
10
+ set :thin_address, nil
11
+ set :thin_command, "thin"
12
+ set(:thin_conf) { "#{shared_path}/thin_cluster.conf" }
13
+ set :thin_environment, "production"
14
+ set :thin_group, nil
15
+ set :thin_log_file, nil
16
+ set :thin_pid_file, nil
17
+ set :thin_port, nil
18
+ set :thin_socket, nil
19
+ set :thin_prefix, nil
20
+ set :thin_servers, 2
21
+ set :thin_user, nil
22
+
23
+ set :thin_uses_bundler, true
24
+
25
+ desc "Prepares application servers for deployment. thin
26
+ configuration is set via the thin_* variables.".cleanup
27
+
28
+ remote_task :setup_app, :roles => :app do
29
+
30
+ raise(ArgumentError, "Please provide either thin_socket or thin_port") if thin_port.nil? && thin_socket.nil?
31
+
32
+ cmd = [
33
+ "config",
34
+ (%(-s "#{thin_servers}") if thin_servers),
35
+ (%(-S "#{thin_socket}") if thin_socket),
36
+ (%(-e "#{thin_environment}") if thin_environment),
37
+ (%(-a "#{thin_address}") if thin_address),
38
+ %(-c "#{current_path}"),
39
+ (%(-C "#{thin_conf}") if thin_conf),
40
+ (%(-P "#{thin_pid_file}") if thin_pid_file),
41
+ (%(-l "#{thin_log_file}") if thin_log_file),
42
+ (%(--user "#{thin_user}") if thin_user),
43
+ (%(--group "#{thin_group}") if thin_group),
44
+ (%(--prefix "#{thin_prefix}") if thin_prefix),
45
+ (%(-p "#{thin_port}") if thin_port),
46
+ ].compact.join ' '
47
+
48
+ thin(cmd)
49
+ end
50
+
51
+ def thin(cmd) # :nodoc:
52
+ command = if thin_uses_bundler
53
+ %(BUNDLE_GEMFILE="#{current_path}/Gemfile" bundle exec #{thin_command} #{cmd} -C "#{thin_conf}")
54
+ else
55
+ %(#{thin_command} #{cmd} -C "#{thin_conf}")
56
+ end
57
+
58
+ %(cd "#{current_path}" && #{command})
59
+ end
60
+
61
+ desc "Restart the app servers"
62
+
63
+ remote_task :start_app, :roles => :app do
64
+ run thin(%(restart -O -s "#{thin_servers}"))
65
+ end
66
+
67
+ desc "Stop the app servers"
68
+
69
+ remote_task :stop_app, :roles => :app do
70
+ run thin(%(stop -s "#{thin_servers}"))
71
+ end
72
+ end
@@ -0,0 +1,59 @@
1
+ %%{
2
+
3
+ machine http_parser_common;
4
+
5
+ #### HTTP PROTOCOL GRAMMAR
6
+ # line endings
7
+ CRLF = "\r\n";
8
+
9
+ # character types
10
+ CTL = (cntrl | 127);
11
+ safe = ("$" | "-" | "_" | ".");
12
+ extra = ("!" | "*" | "'" | "(" | ")" | ",");
13
+ reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");
14
+ sorta_safe = ("\"" | "<" | ">");
15
+ unsafe = (CTL | " " | "#" | "%" | sorta_safe);
16
+ national = any -- (alpha | digit | reserved | extra | safe | unsafe);
17
+ unreserved = (alpha | digit | safe | extra | national);
18
+ escape = ("%" "u"? xdigit xdigit);
19
+ uchar = (unreserved | escape | sorta_safe);
20
+ pchar = (uchar | ":" | "@" | "&" | "=" | "+");
21
+ tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
22
+
23
+ # elements
24
+ token = (ascii -- (CTL | tspecials));
25
+
26
+ # URI schemes and absolute paths
27
+ scheme = ( "http"i ("s"i)? );
28
+ hostname = ((alnum | "-" | "." | "_")+ | ("[" (":" | xdigit)+ "]"));
29
+ host_with_port = (hostname (":" digit*)?);
30
+ userinfo = ((unreserved | escape | ";" | ":" | "&" | "=" | "+")+ "@")*;
31
+
32
+ path = ( pchar+ ( "/" pchar* )* ) ;
33
+ query = ( uchar | reserved )* %query_string ;
34
+ param = ( pchar | "/" )* ;
35
+ params = ( param ( ";" param )* ) ;
36
+ rel_path = (path? (";" params)? %request_path) ("?" %start_query query)?;
37
+ absolute_path = ( "/"+ rel_path );
38
+ path_uri = absolute_path > mark %request_uri;
39
+ Absolute_URI = (scheme "://" userinfo host_with_port path_uri);
40
+
41
+ Request_URI = ((absolute_path | "*") >mark %request_uri) | Absolute_URI;
42
+ Fragment = ( uchar | reserved )* >mark %fragment;
43
+ Method = ( upper | digit | safe ){1,20} >mark %request_method;
44
+
45
+ http_number = ( digit+ "." digit+ ) ;
46
+ HTTP_Version = ( "HTTP/" http_number ) >mark %request_http_version ;
47
+ Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ;
48
+
49
+ field_name = ( token -- ":" )+ >start_field %write_field;
50
+
51
+ field_value = any* >start_value %write_value;
52
+
53
+ message_header = field_name ":" " "* field_value :> CRLF;
54
+
55
+ Request = Request_Line ( message_header )* ( CRLF @done );
56
+
57
+ main := Request;
58
+
59
+ }%%
@@ -0,0 +1,14 @@
1
+ #ifndef ext_help_h
2
+ #define ext_help_h
3
+
4
+ #define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "NULL found for " # T " when shouldn't be.");
5
+ #define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
6
+ #define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T);
7
+
8
+ #ifdef DEBUG
9
+ #define TRACE() fprintf(stderr, "> %s:%d:%s\n", __FILE__, __LINE__, __FUNCTION__)
10
+ #else
11
+ #define TRACE()
12
+ #endif
13
+
14
+ #endif
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("thin_parser")
4
+ have_library("c", "main")
5
+
6
+ create_makefile("thin_parser")