public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
Add a sample configuration and help for using Thin with the Solaris SMF 
monitoring framework.
grempe (author)
Thu Mar 20 15:58:47 -0700 2008
commit  1e7d9b9926bb8fecf42ac06987f9aae739952d3a
tree    76c675f8231d3d39d12af2ac2e0d43bc463a8809
parent  13bb5800368e0965fc08d8eefdcb0f74acb23ebf
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
0
@@ -1 +1,36 @@
0
+<?xml version='1.0'?>
0
+<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
0
+<service_bundle type='manifest' name='thin/<%= service_name %>-production'>
0
+ <service name='network/thin/<%= service_name %>-production' type='service' version='0'>
0
+ <!-- Dependancies for all Thin servers. -->
0
+ <dependency name='fs' grouping='require_all' restart_on='none' type='service'>
0
+ <service_fmri value='svc:/system/filesystem/local'/>
0
+ </dependency>
0
+ <dependency name='net' grouping='require_all' restart_on='none' type='service'>
0
+ <service_fmri value='svc:/network/loopback'/>
0
+ <!-- uncomment the following line if you are on an L+ Accelerator since /home is mounted through nfs -->
0
+ <!--<service_fmri value='svc:/network/nfs/client'/>-->
0
+ </dependency>
0
+ <% 0.upto(thin_max_instances - 1) do |instance| %>
0
+ <!-- instance names can't start with digits. Bummer. -->
0
+ <instance name='i_<%= instance.to_s %>' enabled='false'>
0
+ <!-- Cause the multi-user milestone to bring these services up -->
0
+ <dependent name='<%= service_name %>_<%= instance.to_s %>_multi-user' restart_on='none' grouping='optional_all'>
0
+ <service_fmri value='svc:/milestone/multi-user'/>
0
+ </dependent>
0
+ <exec_method name='start' type='method'
0
+ exec='/opt/csw/bin/thin -C config/thin.yml --only <%= instance.to_s %> start'
0
+ timeout_seconds='10'>
0
+ <method_context working_directory='<%= working_directory %>'>
0
+ <method_credential user='<%= user %>' group='<%= group %>' />
0
+ <method_environment>
0
+ <envvar name='PATH' value='/usr/bin:/bin:/opt/csw/bin' />
0
+ </method_environment>
0
+ </method_context>
0
+ </exec_method>
0
+ <exec_method name='stop' type='method' exec=':kill' timeout_seconds='10' />
0
+ </instance>
0
+ <% end %>
0
+ </service>
0
+</service_bundle>
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
0
@@ -1 +1,151 @@
0
+Using Thin with Solaris' SMF Monitoring Framework
0
+- - - - - - - - - - - - - - - - - - - - - - - - -
0
+
0
+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.
0
+
0
+The sample XML file (thin_solaris_smf.erb) is an example SMF manifest which I use on a Joyent accelerator which runs on OpenSolaris.
0
+
0
+This setup will:
0
+
0
+- ensure the right dependencies are loaded
0
+- 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').
0
+
0
+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.
0
+
0
+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.
0
+
0
+Here are some examples for usage to get you started with Capistrano, and Thin:
0
+
0
+FILE : config/deploy.rb
0
+--
0
+
0
+ require 'config/accelerator/accelerator_tasks'
0
+
0
+ set :application, "yourapp"
0
+ set :svcadm_bin, "/usr/sbin/svcadm"
0
+ set :svccfg_bin, "/usr/sbin/svccfg"
0
+ set :svcs_bin, "/usr/bin/svcs"
0
+
0
+ # gets the list of remote service SMF names that we need to start
0
+ # like (depending on thin_max_instances settings):
0
+ # svc:/network/thin/yourapp-production:i_0
0
+ # svc:/network/thin/yourapp-production:i_1
0
+ # svc:/network/thin/yourapp-production:i_2
0
+ set :service_list, "`svcs -H -o FMRI svc:network/thin/#{application}-production`"
0
+
0
+ # how many Thin instances should be setup to run?
0
+ # this affects the generated thin smf file, and the nginx vhost conf
0
+ # need to re-run setup for thin smf and nginx vhost conf when changed
0
+ set :thin_max_instances, 3
0
+
0
+ # OVERRIDE STANDARD TASKS
0
+ desc "Restart the entire application"
0
+ deploy.task :restart do
0
+ accelerator.thin.restart
0
+ accelerator.nginx.restart
0
+ end
0
+
0
+ desc "Start the entire application"
0
+ deploy.task :start do
0
+ accelerator.thin.restart
0
+ accelerator.nginx.restart
0
+ end
0
+
0
+ desc "Stop the entire application"
0
+ deploy.task :stop do
0
+ accelerator.thin.disable
0
+ accelerator.nginx.disable
0
+ end
0
+
0
+
0
+FILE : config/accelerator/accelerator_tasks.rb
0
+--
0
+
0
+ desc "Create and deploy Thin SMF config"
0
+ task :create_thin_smf, :roles => :app do
0
+ service_name = application
0
+ working_directory = current_path
0
+ template = File.read("config/accelerator/thin_solaris_smf.erb")
0
+ buffer = ERB.new(template).result(binding)
0
+ put buffer, "#{shared_path}/#{application}-thin-smf.xml"
0
+ sudo "#{svccfg_bin} import #{shared_path}/#{application}-thin-smf.xml"
0
+ end
0
+
0
+ desc "Delete Thin SMF config"
0
+ task :delete_thin_smf, :roles => :app do
0
+ accelerator.thin.disable
0
+ sudo "#{svccfg_bin} delete /network/thin/#{application}-production"
0
+ end
0
+
0
+ desc "Show all SMF services"
0
+ task :svcs do
0
+ run "#{svcs_bin} -a" do |ch, st, data|
0
+ puts data
0
+ end
0
+ end
0
+
0
+ desc "Shows all non-functional SMF services"
0
+ task :svcs_broken do
0
+ run "#{svcs_bin} -vx" do |ch, st, data|
0
+ puts data
0
+ end
0
+ end
0
+
0
+
0
+ namespace :thin do
0
+
0
+ desc "Disable all Thin servers"
0
+ task :disable, :roles => :app do
0
+ # temporarily disable, until next reboot (-t)
0
+ sudo "#{svcadm_bin} disable -t #{service_list}"
0
+ end
0
+
0
+ desc "Enable all Thin servers"
0
+ task :enable, :roles => :app do
0
+ # start the app with all recursive dependencies
0
+ sudo "#{svcadm_bin} enable -r #{service_list}"
0
+ end
0
+
0
+ desc "Restart all Thin servers"
0
+ task :restart, :roles => :app do
0
+ # svcadm restart doesn't seem to work right, so we'll brute force it
0
+ disable
0
+ enable
0
+ end
0
+
0
+ end # namespace thin
0
+
0
+
0
+FILE : config/thin.yml
0
+--
0
+
0
+---
0
+pid: tmp/pids/thin.pid
0
+socket: /tmp/thin.sock
0
+log: log/thin.log
0
+max_conns: 1024
0
+timeout: 30
0
+chdir: /your/app/dir/rails/root
0
+environment: production
0
+max_persistent_conns: 512
0
+daemonize: true
0
+servers: 3
0
+
0
+
0
+FILE : config/accelerator/thin_solaris_smf.erb
0
+--
0
+This is of course an example. It works for me, but YMMV
0
+
0
+You may need to change this line to match your environment and config:
0
+ exec='/opt/csw/bin/thin -C config/thin.yml --only <%= instance.to_s %> start'
0
+
0
+
0
+CONTRIBUTE:
0
+
0
+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.
0
+
0
+Cheers,
0
+
0
+Glenn Rempe
0
+2008/03/20

Comments

    No one has commented yet.