chef-client无法启动服务

时间:2015-03-14 02:15:58

标签: ruby apache chef

我正在使用厨师的opscode教程从菜谱中启动服务。该服务是apache2,该cookbook名为“learn_chef_apache2”

package 'apache2'

service 'apache2' do
    action [:start, :enable]
end

template '/var/www/html/index.html' do
    source 'index.html.erb'
end

根据我的理解,这应该安装apache2如果没有安装,启动并启用apache2如果它没有运行并在/ var / www / html /文件夹中创建index.html文件。

这会报告它成功运行。但是,这是我的结果。

akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ sudo chef-client --local-mode --runlist 'recipe[learn_chef_apache2]'
[2015-03-13T22:13:55-04:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["learn_chef_apache2"]
Synchronizing Cookbooks:
  - learn_chef_apache2
Compiling Cookbooks...
Converging 3 resources
Recipe: learn_chef_apache2::default
  * apt_package[apache2] action install (up to date)
  * service[apache2] action start (up to date)
  * service[apache2] action enable (up to date)
  * template[/var/www/html/index.html] action create (up to date)

Running handlers:
Running handlers complete
Chef Client finished, 0/4 resources updated in 1.916971556 seconds
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ service apache2 status * apache2 is not running
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ 

可在此处找到该教程:https://learn.chef.io/learn-the-basics/ubuntu/make-your-recipe-more-manageable/


akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS"
NAME="Ubuntu"
VERSION="14.04.2 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.2 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ chef
chef         chef-apply   chef-client  chef-shell   chef-solo    
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ chef
chef         chef-apply   chef-client  chef-shell   chef-solo    
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ chef
chef         chef-apply   chef-client  chef-shell   chef-solo    
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ chef-client -v
Chef: 12.0.3
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ 

1 个答案:

答案 0 :(得分:2)

似乎在启动"停止"通过食谱或sudo service apache2 stop

另一个食谱将会" NOT"能够启动服务备份。而不是使用" start"我不得不使用" restart"让它发挥作用。

    package 'apache2'

service 'apache2' do
    action [:stop, :enable]
end

template '/var/www/html/index.html' do
    source 'index.html.erb'
end

akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ sudo chef-client --local-mode --runlist 'recipe[learn_chef_apache2]'
[2015-03-14T11:28:28-04:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["learn_chef_apache2"]
Synchronizing Cookbooks:
  - learn_chef_apache2
Compiling Cookbooks...
Converging 3 resources
Recipe: learn_chef_apache2::default
  * apt_package[apache2] action install (up to date)
  * service[apache2] action stop
    - stop service service[apache2]
  * service[apache2] action enable (up to date)
  * template[/var/www/html/index.html] action create (up to date)

Running handlers:
Running handlers complete
Chef Client finished, 1/4 resources updated in 3.538150111 seconds
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ 
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ sudo service apache2 status * apache2 is not running
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ 

在这里,我发起了"开始"行动不起作用。

package 'apache2'

service 'apache2' do
    action [:start, :enable]
end

template '/var/www/html/index.html' do
    source 'index.html.erb'
end

akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ sudo chef-client --local-mode --runlist 'recipe[learn_chef_apache2]'
[2015-03-14T11:35:43-04:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["learn_chef_apache2"]
Synchronizing Cookbooks:
  - learn_chef_apache2
Compiling Cookbooks...
Converging 3 resources
Recipe: learn_chef_apache2::default
  * apt_package[apache2] action install (up to date)
  * service[apache2] action start (up to date)
  * service[apache2] action enable (up to date)
  * template[/var/www/html/index.html] action create (up to date)

Running handlers:
Running handlers complete
Chef Client finished, 0/4 resources updated in 2.524905132 seconds
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ sudo service apache2 status * apache2 is not running
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ 

在这里,我执行了#34;重启"这确实有用。

package 'apache2'

service 'apache2' do
    action [:restart, :enable]
end

template '/var/www/html/index.html' do
    source 'index.html.erb'
end

akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ sudo chef-client --local-mode --runlist 'recipe[learn_chef_apache2]'
[2015-03-14T11:32:52-04:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["learn_chef_apache2"]
Synchronizing Cookbooks:
  - learn_chef_apache2
Compiling Cookbooks...
Converging 3 resources
Recipe: learn_chef_apache2::default
  * apt_package[apache2] action install (up to date)
  * service[apache2] action restart
    - restart service service[apache2]
  * service[apache2] action enable (up to date)
  * template[/var/www/html/index.html] action create (up to date)

Running handlers:
Running handlers complete
Chef Client finished, 1/4 resources updated in 3.468081078 seconds
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$ sudo service apache2 status
 * apache2 is running
akhter@akhter-GA-990FXA-UD3:~/chef-repo/cookbooks$