Chef, cómo ejecutar una plantilla que crea un init.d script antes de crear el servicio
A continuación está mi templete para nginx.
Me enfrento a una captura 22. Necesito instalar un init.d plantilla. Así que tengo una plantilla nginx erb que coloco en /etc / init.d / nginx.
Incluso intenté colocar el código encima de la receta. La receta depende del inicio.archivo d pero no se ejecuta hasta que es demasiado tarde y como resultado obtengo este error:
STDERR: update-rc.d: /etc/init.d/nginx: file does not exist
---- End output of "bash" "/tmp/chef-script20120330-26326-3ologp-0" ----
Ran "bash" "/tmp/chef-script20120330-26326-3ologp-0" returned 1
[Fri, 30 Mar 2012 06:22:15 +0000] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[Fri, 30 Mar 2012 06:22:15 +0000] ERROR: Sleeping for 60 seconds before trying again
En la siguiente ejecución de chef client, las cosas funcionan porque entonces se creó el templete.
¿Cómo puedo ejecutar un plantilla inmediatamente antes de registrar el recurso de servicio para nginx? Una solución rápida es que creo una receta que ejecutará la plantilla antes de nginx para instalar la plantilla, pero eso parece bastante absurdo.
Este tempate debe instalarse antes de registrar el servicio.
template "nginx" do
path "/etc/init.d/nginx"
source "nginx.erb"
owner "root"
group "root"
mode "0755"
end
Luego registre el servidor.
service "nginx" do
supports :restart => true, :start => true, :stop => true, :reload => true
action [ :enable, :start]
end
####################################
#Install Nginx
####################################
#http://wiki.nginx.org/HttpLuaModule#Installation
version = node[:nginx][:version]
package "libpcre3" do
action :install
end
package "libpcre3-dev" do
action :install
end
package "libpcre++-dev" do
action :install
end
package "openssl" do
action :install
end
template "nginx" do
path "/etc/init.d/nginx"
source "nginx.erb"
owner "root"
group "root"
mode "0755"
end
#mkdir /var/log/nginx
directory "/var/log/nginx" do
owner "root"
group "root"
mode "0755"
action :create
#not_if "test -f /etc/nginx/lock"
end
remote_file "/tmp/nginx-#{version}.tar.gz" do
source "http://nginx.org/download/nginx-#{version}.tar.gz"
checksum node[:nginx][:checksum]
action :create_if_missing
notifies :run, "bash[install_nginx]", :immediately
end
bash "install_nginx" do
user "root"
cwd "/tmp"
code <<-EOH
tar -xvf nginx-#{version}.tar.gz
cd nginx-#{version}
./configure --with-http_stub_status_module
make -j2
make install
ln -s /usr/local/nginx/conf/ /etc/nginx
/usr/sbin/update-rc.d -f nginx defaults
EOH
action :nothing
creates "/usr/sbin/nginx"
notifies :restart, "service[nginx]"
#not_if "test -f /etc/redis/lock"
end
service "nginx" do
supports :restart => true, :start => true, :stop => true, :reload => true
action [ :enable, :start]
end
#ln -s /usr/local/nginx/conf/ /etc/nginx
#link "/usr/local/nginx/conf/" do
# to "/etc/nginx"
# link_type :hard
#end
link "/usr/local/nginx/logs/access.log" do
to "/var/log/nginx/access.log"
end
link "/usr/local/nginx/logs/error.log" do
to "/var/log/nginx/error.log"
end
file "/etc/nginx/lock" do
owner "root"
group "root"
mode "0755"
action :create_if_missing
end
template "nginx.conf" do
path "/etc/nginx/nginx.conf"
source "nginx.conf.erb"
owner "root"
group "root"
mode "0644"
#notifies :reload, "service[nginx]"
notifies :reload, resources(:service => "nginx"), :immediately
end
Gracias
3 answers
Puede establecer la acción en el servicio en :nada. Luego haga que la plantilla notifique al servicio para habilitar. De esta manera se procesará la plantilla y luego se habilitará el servicio:
service "nginx" do
supports :restart => true, :start => true, :stop => true, :reload => true
action :nothing
end
template "nginx" do
path "/etc/init.d/nginx"
source "nginx.erb"
owner "root"
group "root"
mode "0755"
notifies :enable, "service[nginx]"
notifies :start, "service[nginx]"
end
Entonces el servicio esperará hasta que la plantilla se haya procesado.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-30 11:21:56
template "nginx" do
path "/etc/init.d/nginx"
source "nginx.erb"
owner "root"
group "root"
mode "0755"
end
service "nginx" do
supports :restart => true, :start => true, :stop => true, :reload => true
action [ :enable, :start ]
subscribes :restart, "template[nginx]", :immediately
end
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-12 07:44:42
Mientras que usar notifies
es mejor en este caso, en otros casos no tienes ese lujo. He aquí cómo instruir a Chef para crear la plantilla inmediatamente:
tpl = template "nginx" do
action :nothing
path "/etc/init.d/nginx"
source "nginx.erb"
owner "root"
group "root"
mode "0755"
end
tpl.run_action(:create)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-23 22:11:32