0
+Using Thin with Solaris' SMF Monitoring Framework
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
+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
+- 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
+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
+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
+Here are some examples for usage to get you started with Capistrano, and Thin:
0
+FILE : config/deploy.rb
0
+ require 'config/accelerator/accelerator_tasks'
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
+ # 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
+ # 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
+ # OVERRIDE STANDARD TASKS
0
+ desc "Restart the entire application"
0
+ deploy.task :restart do
0
+ accelerator.thin.restart
0
+ accelerator.nginx.restart
0
+ desc "Start the entire application"
0
+ accelerator.thin.restart
0
+ accelerator.nginx.restart
0
+ desc "Stop the entire application"
0
+ accelerator.thin.disable
0
+ accelerator.nginx.disable
0
+FILE : config/accelerator/accelerator_tasks.rb
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
+ 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
+ desc "Show all SMF services"
0
+ run "#{svcs_bin} -a" do |ch, st, data|
0
+ desc "Shows all non-functional SMF services"
0
+ run "#{svcs_bin} -vx" do |ch, st, data|
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
+ 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
+ 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
+chdir: /your/app/dir/rails/root
0
+environment: production
0
+max_persistent_conns: 512
0
+FILE : config/accelerator/thin_solaris_smf.erb
0
+This is of course an example. It works for me, but YMMV
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
+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.
Comments
No one has commented yet.