diff --git a/attributes/default.rb b/attributes/default.rb index 2190091..fa77ded 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -87,3 +87,10 @@ def default_postrgres_port default['razor']['rubygems_source']['version'] = src_version = "1.8.24" default['razor']['rubygems_source']['url'] = "http://files.rubyforge.vm.bytemark.co.uk/rubygems/rubygems-#{src_version}.tgz" + +case node['platform'] +when "ubuntu" + default['razor']['service_type'] = "upstart" +else + default['razor']['service_type'] = "sysvinit" +end diff --git a/recipes/_app.rb b/recipes/_app.rb index 8757075..7aa4527 100644 --- a/recipes/_app.rb +++ b/recipes/_app.rb @@ -80,18 +80,3 @@ notifies :restart, "service[razor]" end - -template "/etc/init.d/razor" do - source "razor.erb" - mode "0755" - variables({ - :directory => install_path - }) - - notifies :restart, "service[razor]" -end - -service "razor" do - supports :status => true, :restart => true, :reload => false - action [ :enable, :start ] -end diff --git a/recipes/_service.rb b/recipes/_service.rb new file mode 100644 index 0000000..f92b9c0 --- /dev/null +++ b/recipes/_service.rb @@ -0,0 +1,54 @@ +# +# Cookbook Name:: razor +# Recipe:: _service +# +# Author:: Fletcher Nichol () +# +# Copyright 2012, Blue Box Group, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +case node['razor']['service_type'] +when "sysvinit" + template "/etc/init.d/razor" do + source "razor.erb" + mode "0755" + variables({ + :directory => node['razor']['install_path'] + }) + + notifies :restart, "service[razor]" + end + + service "razor" do + supports :status => true, :restart => true, :reload => false + action [ :enable, :start ] + end +when "upstart" + template "/etc/init/razor.conf" do + source "razor.upstart.erb" + mode "0644" + variables( + :install_path => node['razor']['install_path'] + ) + notifies :stop, "service[razor]" + notifies :start, "service[razor]" + end + + service "razor" do + provider Chef::Provider::Service::Upstart + supports :status => true, :restart => true, :reload => false + action [ :enable, :start ] + end +end diff --git a/recipes/default.rb b/recipes/default.rb index 4112617..3ad0d57 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -29,4 +29,5 @@ include_recipe 'razor::_nodejs' include_recipe 'razor::_ruby_from_package' include_recipe 'razor::_app' +include_recipe 'razor::_service' include_recipe 'razor::_add_images' diff --git a/templates/default/razor.upstart.erb b/templates/default/razor.upstart.erb new file mode 100644 index 0000000..3cdf25e --- /dev/null +++ b/templates/default/razor.upstart.erb @@ -0,0 +1,14 @@ +description "Razor" +author "Guilhem Lettron " + +start on runlevel [2345] +stop on runlevel [!2345] + +respawn # respawn the service if it dies + +#script +# export RBENV_ROOT="/opt/rbenv" # set required rbenv variable +# exec ${RBENV_ROOT}/bin/rbenv exec <%= ::File.join(@install_path, "bin", "razor_daemon.rb") %> start --ontop +#end script + +exec <%= ::File.join(@install_path, "bin", "razor_daemon.rb") %> start --ontop