2012-03-29 88 views
4

我做了一個安裝phpunit的vagrant的配方,但是當我使用vagrant暫停然後流浪時,它仍然失敗。如何阻止廚師食譜完成時運行

execute "discover phpunit" do 
    command "pear channel-discover pear.phpunit.de" 
    action :run 
end 

execute "config phpunit" do 
    command "pear config-set auto_discover 1" 
    action :run 
end 

execute "install phpunit" do 
    command "pear install pear.phpunit.de/PHPUnit" 
    action :run 
end 

我得到:

[default] [Thu, 29 Mar 2012 14:39:57 -0700] ERROR: execute[discover phpunit] (phpunit::default line 39) has had an error 
[Thu, 29 Mar 2012 14:39:57 -0700] ERROR: execute[discover phpunit] (/tmp/vagrant-chef-1/chef-solo-1/phpunit/recipes/default.rb:39:in `from_file') had an error: 
execute[discover phpunit] (phpunit::default line 39) had an error: Chef::Exceptions::ShellCommandFailed: Expected process to exit with [0], but received '1' 
---- Begin output of pear channel-discover pear.phpunit.de ---- 
STDOUT: Channel "pear.phpunit.de" is already initialized 
+0

您使用的是哪一版本的vagrant? – 2012-03-29 21:45:26

+0

@MichaelIrey版本0.8.7 – NathanBrakk 2012-03-29 21:46:44

回答

4

它看起來像正在發生的事情是該腳本正在運行的每個執行vagrant up時間。

你可能想是這樣的:

execute "discover phpunit" do 
    command "pear channel-discover pear.phpunit.de" 
    action :run 
    not_if "which phpunit" 
end 

只要確保phpunit是你$PATH

+0

的確如此。好的!這裏有另一個問題:如果它有phpunit,我怎麼才能讓它退出配方? – NathanBrakk 2012-03-29 21:55:48

+0

@NathanBrakk真的沒有辦法(我知道)「退出」一個配方,因爲它基本上是一個程序腳本 – Andrew 2012-04-09 16:48:43

+1

換句話說:這取決於你如何使你的食譜冪等。 – manojlds 2012-04-19 10:37:56

0

我想大概是not_if設置爲

not_if { File.exists?('/path/to/phpunit') 

而不是依賴於它在$ PATH中找到。