【问题标题】:systemctl error in docker 'Failed to connect to bus: No such file or directory'docker中的systemctl错误'无法连接到总线:没有这样的文件或目录'
【发布时间】:2018-05-14 14:35:41
【问题描述】:

我正在使用 Ubuntu-16.04 映像和 docker 在本地测试我的食谱。在执行kitchen converge 时,我收到以下错误。我发现systemctl 工作不正常。有人可以帮我解决这个问题任何其他方式来实现同样的事情吗?

 [2017-11-30T15:22:30+00:00] INFO: Running queued delayed notifications before re-raising exception

 Running handlers:
   [2017-11-30T15:22:30+00:00] ERROR: Running exception handlers
   Running handlers complete
   [2017-11-30T15:22:30+00:00] ERROR: Exception handlers complete
   Chef Client failed. 9 resources updated in 06 seconds
   [2017-11-30T15:22:30+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
   [2017-11-30T15:22:30+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
   [2017-11-30T15:22:30+00:00] ERROR: envoy_auth_apps_setup[default-service] (envoy_auth_apps::_default line 1) had an error: Chef::Exceptions::MultipleFailures: Multiple failures occurred:
   * Mixlib::ShellOut::ShellCommandFailed occurred in chef run: execute[systemctl daemon-reload] (/tmp/kitchen/cache/cookbooks/envoy_auth_apps/resources/setup.rb line 133) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
   ---- Begin output of systemctl daemon-reload ----
   STDOUT:
   STDERR: Failed to connect to bus: No such file or directory
   ---- End output of systemctl daemon-reload ----
   Ran systemctl daemon-reload returned 1
   * Mixlib::ShellOut::ShellCommandFailed occurred in delayed notification: service[envoy] (/tmp/kitchen/cache/cookbooks/envoy_auth_apps/resources/setup.rb line 194) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
   ---- Begin output of /bin/systemctl --system restart envoy ----
   STDOUT:
   STDERR: Failed to connect to bus: No such file or directory
   ---- End output of /bin/systemctl --system restart envoy ----
   Ran /bin/systemctl --system restart envoy returned 1

   [2017-11-30T15:22:30+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
 >>>>>> ------Exception-------
 >>>>>> Class: Kitchen::ActionFailed
 >>>>>> Message: 1 actions failed.
 >>>>>>     Converge failed on instance <default-ubuntu>.  Please see .kitchen/logs/default-ubuntu.log for more details
 >>>>>> ----------------------
 >>>>>> Please see .kitchen/logs/kitchen.log for more details
 >>>>>> Also try running `kitchen diagnose --all` for configuration

这是我的.kitchen.yml

---

driver:
  name: docker
  binary: /usr/local/bin/docker
  use_sudo: false
  network:
    - ["public_network", "bridge: 'en0: Wi-Fi (AirPort)'"]

provisioner:
  name: chef_zero
  require_chef_omnibus: "12.21.14"
  environments_path: test/integration/environments
  nodes_path: test/integration/nodes
  data_bags_path: test/integration/data_bags
  client_rb:
    environment: development

verifier:
  name: inspec

platforms:
  - name: ubuntu
    driver_config:
      image: ubuntu:xenial
      platform: ubuntu
#     provision_command:
#       - apt-get -y install dbus

suites:
  - name: default
    run_list:
#   - recipe[base_app]
        - recipe[envoy_auth_apps::_default]
    verifier:
      inspec_tests:
        - test/integration/default
attributes:
  nameserver:
    domain_name: 'kitchen.xyz.io'
  envoy_auth_apps:
    consul_client_enabled: false

【问题讨论】:

  • systemctl 仅在您运行 systemd 时才有效,并且在 docker 容器中使用 systemd 并不是一个特别好的主意——Docker 方式是直接调用容器应该运行的单个服务,而不是在每个容器中都有一个初始化系统。

标签: docker chef-infra cookbook test-kitchen systemctl


【解决方案1】:

是的,还有另一种方法可以达到同样的效果!您可以尝试用https://github.com/gdraheim/docker-systemctl-replacement 替换标准的systemd systemctl ...虽然它可以在数量惊人的环境中工作,但到目前为止还没有在厨房中进行过测试。如果您尝试一下,请提供一些反馈。

【讨论】:

    【解决方案2】:

    通常 docker 不支持容器中的 systemd 服务,但您可以使用特殊的 ubuntu systemd 映像和一些额外的主机配置。请注意,此图像不建议在生产环境中运行。

    首先,你需要设置你的主机来运行这个镜像:

    docker run --rm --privileged -v /:/host solita/ubuntu-systemd setup

    然后,您将能够使用systemd 运行容器(添加必要的挂载和标志):

    docker run -d --name systemd --security-opt seccomp=unconfined \
     --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
     -t solita/ubuntu-systemd
    

    【讨论】:

    • Test Kitchen 是一个集成测试套件,而不是生产系统 :)
    • 我尝试使用ubuntu-systemd 图像,但它不起作用。给出与我上面显示的相同的错误。此图像适用于 systemd,但在我的情况下是 systemctl。是不是有问题?
    • systemd 是一个初始化系统和系统管理器,而 systemctl 是一个命令行工具来管理 systemd 服务。我添加了一些可以帮助您实现目标的版本。
    • 实际上,systemctl 使用 d-bus 与 systemd 守护进程对话,后者反过来管理服务。 systemctl 工具本身就很笨。
    【解决方案3】:

    kitchen-docker 并没有真正设置为与 systemd 一起使用。我建议改用kitchen-dokken,这样设置起来相当容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      • 2018-02-09
      • 1970-01-01
      • 2018-01-30
      相关资源
      最近更新 更多