gpt4 book ai didi

chef-infra - Chef,如何在创建服务之前运行创建 init.d 脚本的模板

转载 作者:行者123 更新时间:2023-12-03 09:20:37 24 4
gpt4 key购买 nike

下面是我的 nginx 模板。

我面临一个问题 22. 我需要安装一个 init.d 模板。所以我有一个 nginx erb 模板放在/etc/init.d/nginx 中。

我什至尝试将代码放在食谱的顶部。该配方依赖于 init.d 文件,但直到为时已晚才执行它,结果我收到此错误:

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

在下一轮厨师客户中,事情会奏效,因为模板被创建了。

如何在为 nginx 注册服务资源之前立即执行模板?一个快速的解决方法是我创建了一个配方,它将在 nginx 之前运行模板来安装模板,但这似乎很荒谬。

这个模板需要在服务注册之前安装。
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]
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

谢谢

最佳答案

您可以将服务上的操作设置为 :nothing。然后让模板通知服务启用。这样模板将被处理,然后服务将被启用:

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

然后服务将等到模板处理完毕。

关于chef-infra - Chef,如何在创建服务之前运行创建 init.d 脚本的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9938314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com