Vagrant 重新加载后 Apache 无法启动 [英] Apache doesn't start after Vagrant reload

查看:24
本文介绍了Vagrant 重新加载后 Apache 无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Vagrant 设置一个简单的开发环境.基本框(我创建的)具有 CentOS 6.5 64 位和 Apache 和 MySQL.

I'm trying to set up a simple dev environment with Vagrant. The base box (that I created) has CentOS 6.5 64bit with Apache and MySQL.

问题是,在我重新加载 VM(vagrant reloadvagrant halt 然后 up).

The issue is, the httpd service doesn't start on boot after I reload the VM (vagrant reload or vagrant halt then up).

该问题仅在我运行更改 DocumentRoot 的配置脚本时出现,并且仅在我第一次停止机器后出现.

The problem only occurs when I run a provision script that alters the DocumentRoot and only after the first time I halt the machine.

httpd 位于 chkconfig 级别 2、3、4 和 5

httpd is on chkconfig on levels 2, 3, 4 and 5

没有错误写入 error_log(在 /etc/httpd/logs 上).

There are no errors written to the error_log (on /etc/httpd/logs).

如果我 ssh 进入机器并手动启动服务,它启动没有问题.

If I ssh into the machine and start the service manually, it starts with no problem.

我在其他 CentOS 机器上遇到了同样的问题(例如 vagrantcloud.com 上的 chef/centos-6.5),这就是我自己创建的原因.

I had the same issue with other CentOS boxes (like the chef/centos-6.5 available on vagrantcloud.com), that's why I created one myself.

其他服务,比如mysql,启动正常,所以是apache特有的问题.

Other services, like mysql, start fine, so it's a problem specific to apache.

  • httpd 总是在第一次启动时启动,即使使用配置脚本(如 vagrant destroy 之后)
  • httpd 总是在我不运行配置脚本时启动(但我需要它来设置 DocumentRoot)
  • 第一次停止后,httpd 无法启动,配置脚本与 DocumentRoot 混淆(不确定是否是问题所在).

这是我的 Vagrantfile:

This is my Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "centos64_lamp"
  config.vm.box_url = "<url>/centos64_lamp.box"
  config.vm.hostname = "machine.dev"
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.synced_folder ".", "/vagrant", owner: "root", group: "root"
  config.vm.provision :shell, :path => "vagrant_files/bootstrap.sh"

end

我尝试使用所有者/组 rootapache 创建 vagrant 文件夹.两者都存在同样的问题(与所有者 vagrant 一样).

I tried to create the vagrant folder with owner/group root and apache. Same problem with both (as with owner vagrant).

这些是我尝试过的配置脚本 (bootstrap.sh).我希望他们做的唯一一件事就是将 DocumentRoot 更改为 vagrant 文件夹.都没有用.

These are the provision scripts (bootstrap.sh) that I tried. The only thing that I want them to do is to change the DocumentRoot to the vagrant folder. Neither worked.

尝试 1

#!/usr/bin/env bash

sudo rm -rf /var/www/html
sudo ln -fs /vagrant/app/webroot /var/www/html

尝试 2

#!/usr/bin/env bash

sudo cp /vagrant/vagrant_files/httpd.conf /etc/httpd/conf
sudo service httpd restart

第二次尝试的 httpd.conf 与默认的相同,除了 DocumentRoot 路径.第二种选择允许我执行 vagrant up --provision 以强制重新启动服务,但这应该是不必要的步骤.

The httpd.conf on the second try is equal to the default one, except for the DocumentRoot path. This second alternative allows me to do vagrant up --provision to force the restart of the service, but that should be an unnecessary step.

我还能尝试什么来解决这个问题?谢谢.

What else can I try to solve this? Thank you.

推荐答案

显然问题是由于 Apache 尝试启动时未安装 vagrant 文件夹.虽然我还是不明白为什么不抛出错误.

Apparently the problem was due to the vagrant folder not being mounted when Apache tries to start. Although I still don't understand why no error is thrown.

我通过创建一个 Upstart 脚本(在文件夹 /etc/init 上)来解决它,以在 vagrant 挂载其文件夹后启动服务(它发出一个名为 vagrant-mounted)

I solved it by creating an Upstart script (on the folder /etc/init) to start the service after vagrant mounts its folder (it emits an event called vagrant-mounted)

这是我使用的脚本(文件名为 httpd.conf,但我认为没有必要).

This is the script I used (with the filename httpd.conf but I don't think that's necessary).

# start apache on vagrant mounted

start on vagrant-mounted

exec sudo service httpd start

Upstart 可以做更多事情,但这可以解决问题.

Upstart can do much more but this solves it.

这篇关于Vagrant 重新加载后 Apache 无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆