bash Vagrant Shell Provisioning 运行但失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24771595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Vagrant Shell Provisioning runs but fails
提问by Aaron Blakeley
I have a simple vagrant box that I am building while working through a tutorial. I have built on the box here is my vagrant file.
我有一个简单的流浪盒子,我在学习教程时正在构建它。我在盒子上建立了我的流浪文件。
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.provision :shell, :path => "bootstrap.sh"
#config.vm.network "forwarded_port", guest: 80, host: 8080
end
This seems to work fine and is waiting for some other configuration but the problem I am having with the provisioning.
这似乎工作正常,正在等待其他一些配置,但我在配置时遇到了问题。
It finds the Shell script fine with no errors. It even builds the vagrant box. However when it finishes I get this error
它发现 Shell 脚本很好,没有错误。它甚至构建了流浪盒子。但是,当它完成时,我收到此错误
==> default: stdin: is not a tty
==> default: bash: /tmp/vagrant-shell: /user/bin/env: bad interpreter: No such file or directory
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
chmod +x /tmp/vagrant-shell && /tmp/vagrant-shell
Stdout from the command:
Stderr from the command:
stdin: is not a tty
bash: /tmp/vagrant-shell: /user/bin/env: bad interpreter: No such file or directory
When I ssh in nothing I setup to install is installed. When I run the bash script in the terminal command by command it works. Here is my bash script.
当我没有设置 ssh 时,我安装了安装。当我通过命令在终端命令中运行 bash 脚本时,它可以工作。这是我的 bash 脚本。
#!/user/bin/env bash
#install
sudo apt-get update
sudo apt-get install -y python-software-properties
sudo add-apt-repository -y ppa:ondrej/php5
sudo apt-get update
sudo apt-get install -y wget php5 apache2 php5-mcrypt php5-curl git
sudo apt-get update
#apache onfig
sudo a2enmod rewrite
#Symlink for local development
#remove the WWW for Apache
sudo rm -rf /var/www
#symlink for local directory ln -fs {PATH TO LOCAL PROJECT} /var/www
sudo ln -fs /pathtolocaldirectory /var/www
#Restart Apache
sudo service apache2 restart
回答by drinkcat
The error message is quite clear actually: /user/bin/env
does not exist.
错误信息实际上很清楚:/user/bin/env
不存在。
Simply replace the first line in your bash script by:
只需将 bash 脚本中的第一行替换为:
#!/usr/bin/env bash
回答by ganeshragav
Your /tmp directory or script itself is missing permission and that might be the root cause of this execution issue.
您的 /tmp 目录或脚本本身缺少权限,这可能是此执行问题的根本原因。
To Solve this , try
要解决此问题,请尝试
chmod 755 /tmp/
chmod +x /tmp/vagrant-shell
And then try to execute the command, it will work safe.
然后尝试执行命令,它会安全地工作。