【问题标题】:chef-client does not start servicechef-client 不启动服务
【发布时间】:2015-03-14 02:15:57
【问题描述】:

我正在使用关于 chef 的 opscode 教程从食谱中启动服务。服务是 apache2,食谱名为“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$ 

【问题讨论】:

  • 以 root 身份检查 apache2 状态的结果是否相同?即:sudo service apache2 status
  • 没错,和“sudo service apache2 status”一样
  • ubuntu@chefnode:~$ sudo service apache2 status ● apache2.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)

标签: ruby apache chef-infra


【解决方案1】:

似乎是通过配方或sudo service apache2 stop启动“停止”时

另一个配方将“不能”启动服务备份。而不是使用“开始”,我不得不使用“重启”来让它工作。

    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$ 

在这里我执行了一个“重启”,它确实有效。

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$ 

【讨论】:

  • 在我的情况下,当我引导节点时,apache 没有安装也没有出错:#knife node show sg_poc_ubu_ChefNode2 节点名称:sg_poc_ubu_ChefNode2 环境:_default FQDN:chefnode.node.com IP:XX.X.X1 .55 运行列表:recipe[learn_chef_apache2] 角色:Recipes:learn_chef_apache2、learn_chef_apache2::default 平台:ubuntu 16.04 标签:
  • u# sudo service apache2 status ● apache2.service Loaded: not-found (Reason: no such file or directory) Active: inactive (dead)
  • 我跑了:#knife bootstrap MYIP --ssh-user ubuntu -i /root/.ssh/keytest_win_singreg.pem --sudo --use-sudo-password --node-name sg_poc_ubu_ChefNode2 --运行列表'recipe[learn_chef_apache2]'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-29
  • 1970-01-01
  • 1970-01-01
  • 2015-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多