Skip to content

Commit

Permalink
adding virtual machine initialization scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyimin committed Apr 29, 2014
1 parent fd0dcd8 commit 21ee3a4
Show file tree
Hide file tree
Showing 143 changed files with 6,833 additions and 3 deletions.
59 changes: 56 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,57 @@
androidtestdebug
================
这是随《[Android应用测试与调试实战](http://www.amazon.cn/%E7%A7%BB%E5%8A%A8%E5%BC%80%E5%8F%91-Android%E5%BA%94%E7%94%A8%E6%B5%8B%E8%AF%95%E4%B8%8E%E8%B0%83%E8%AF%95%E5%AE%9E%E6%88%98-%E6%96%BD%E6%87%BF%E6%B0%91/dp/B00JPUUATC/ref=tmm_pap_title_0?ie=UTF8&qid=1398769605&sr=8-1)》附带的示例代码,**欢迎购买我新书的读者下载** - 没有购买的网友也可以下载。

Sample code & support site for my book android test & debug
有两个方法下载书中提到的虚拟机:

1. [虚拟机的下载地址](http://aqkwdkgcpv.l55.yunpan.cn/lk/QNpYuw7QWu8gK), 访问密码 10eb 。
2. 按下面的方式从本源码自动创建并部署一个虚拟机,;)。

### 使用说明
1. 下载并安装最新的Virtual Box: https://www.virtualbox.org/wiki/Downloads
2. 下载并安装最新的Vagrant: http://vagrantup.com/
3. 第一次运行时,打开命令行,进入源代码的根目录,执行(如果是windows平台,在下面的命令后面加.bat后缀):

-----------------------

vagrant box add base http://files.vagrantup.com/lucid32.box
vagrant up
-----------------------

`有时因为“长城”的关系,下载过程会中断,建议先将http://files.vagrantup.com/lucid32.box下载到本机,例如d:\lucid32.box,然后运行更改过的命令创建:`

-----------------------

vagrant box add base d:\lucid32.box
vagrant up
-----------------------


4. 下次就只需要执行下面的命令就可以使用:

-----------------------

vagrant up
-----------------------

5. 命令运行完毕后,一会功夫就可以看到虚拟机界面,第一次运行的时候,因为需要从网上下载安装不少软件,应该只能看到命令行界面,要耐心等待命令运行完毕,运行完命令后,就可以使用虚拟机了。

6. 如果需要进入命令行调试的话,在windows平台,用putty登录:127.0.0.1:2222,用户名/密码:vagrant/vagrant

6. 在非Windows平台

-----------------------

vagrant ssh
-----------------------

7. 进入示例代码工作主目录 - 这个虚拟机上的主目录是你宿主机执行vagrant命令的目录

-----------------------

cd /vagrant
ls
-----------------------
20 changes: 20 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant::Config.run do |config|
config.vm.define :server do |server_config|
server_config.vm.box = "base"
server_config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "vagrant_main"
chef.add_recipe "java"
chef.add_recipe "maven"
end

server_config.vm.network :hostonly, "192.168.2.10"
server_config.vm.forward_port 80, 5886
server_config.vm.forward_port 5005, 5005
end

config.vm.boot_mode = :gui
end
78 changes: 78 additions & 0 deletions cookbooks/apache2/README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
= DESCRIPTION:

Complete Debian/Ubuntu style Apache2 configuration.

= REQUIREMENTS:

Debian or Ubuntu preferred.

Red Hat/CentOS and Fedora can be used but will be converted to a Debian/Ubuntu style Apache as it's far easier to manage with chef.

= ATTRIBUTES:

The file attributes/apache.rb contains the following attribute types:

* platform specific locations and settings.
* general settings
* prefork attributes
* worker attributes

General settings and prefork/worker attributes are tunable.

= USAGE:

Include the apache2 recipe to install Apache2 and get 'sane' default settings. Configuration is modularized through Apache vhost sites a la Debian style configuration.

For Red Hat, CentOS and Fedora you should first disable selinux as it's not supported (yet), then remove the stock httpd and all it's dependencies prior to attempting to use this recipe. Many packages in these distributions drop conflicting configs into conf.d, all of which haven't been accounted for yet. Starting from scratch will also make it far easier to debug.

== Defines:

* apache_module: sets up an Apache module.
* apache_conf: sets up a config file for an apache module.
* apache_site: sets up a vhost site. The conf file must be available.
* web_app: copies the template for a web app and enables it as a site via apache_site.

== Web Apps:

Various applications that can be set up with Apache as the front end, such as PHP, Django, Rails and others can use the web_app define to set up the template and the Apache site. The define is kind of dumb, so the template needs have the application implementation settings, since we don't know what your app is or what is needed from Apache.

We only prototype one parameter for the web_app define, "template". This is used to specify the name of the template to use in the current cookbook. When you use web_app, you can set up any parameters you want to use in your template. They will get passed to the template through the params hash. For example, the sample web_app.conf.erb template in this cookbook makes use of these.

* docroot
* server_name
* server_aliases

These are available as @params[:docroot], @params[:server_name], @params[:server_aliases] within the template.

If 'cookbook' and 'template' are not specified, the current cookbook's templates/default/web_app.conf.erb will be used. If this template is not suitable for your application, copy it to your cookbook and customize as needed.

== God Monitor:

There's a new recipe, apache2::god_monitor. You will need to make sure to include the 'god' recipe before using the apache2::god_monitor recipe in your cookbook.

== OpenID Auth

Installs the mod_auth_openid module from source. Specify an array of OpenIDs that are allowed to authenticate with the attribute apache[:allowed_openids]. Use the following in a vhost to protect with OpenID authentication:

AuthOpenIDEnabled On
AuthOpenIDDBLocation /var/cache/apache2/mod_auth_openid.db
AuthOpenIDUserProgram /usr/local/bin/mod_auth_openid.rb

Change the DBLocation as appropriate for your platform. You'll need to change the file in the recipe to match. The UserProgram is optional if you don't want to limit access by certain OpenIDs.

= LICENSE & AUTHOR:

Author:: Joshua Timberman (<joshua@opscode.com>)
Copyright:: 2009, Opscode, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
77 changes: 77 additions & 0 deletions cookbooks/apache2/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#
# Cookbook Name:: apache2
# Attributes:: apache
#
# Copyright 2008-2009, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Where the various parts of apache are
case platform
when "redhat","centos","fedora","suse"
set[:apache][:dir] = "/etc/httpd"
set[:apache][:log_dir] = "/var/log/httpd"
set[:apache][:user] = "apache"
set[:apache][:binary] = "/usr/sbin/httpd"
set[:apache][:icondir] = "/var/www/icons/"
when "debian","ubuntu"
set[:apache][:dir] = "/etc/apache2"
set[:apache][:log_dir] = "/var/log/apache2"
set[:apache][:user] = "www-data"
set[:apache][:binary] = "/usr/sbin/apache2"
set[:apache][:icondir] = "/usr/share/apache2/icons"
else
set[:apache][:dir] = "/etc/apache2"
set[:apache][:log_dir] = "/var/log/apache2"
set[:apache][:user] = "www-data"
set[:apache][:binary] = "/usr/sbin/apache2"
set[:apache][:icondir] = "/usr/share/apache2/icons"
end

###
# These settings need the unless, since we want them to be tunable,
# and we don't want to override the tunings.
###

# General settings
default[:apache][:listen_ports] = [ "80","443" ]
default[:apache][:contact] = "ops@example.com"
default[:apache][:timeout] = 300
default[:apache][:keepalive] = "On"
default[:apache][:keepaliverequests] = 100
default[:apache][:keepalivetimeout] = 5

# Security
default[:apache][:servertokens] = "Prod"
default[:apache][:serversignature] = "On"
default[:apache][:traceenable] = "On"

# mod_auth_openids
default[:apache][:allowed_openids] = Array.new

# Prefork Attributes
default[:apache][:prefork][:startservers] = 16
default[:apache][:prefork][:minspareservers] = 16
default[:apache][:prefork][:maxspareservers] = 32
default[:apache][:prefork][:serverlimit] = 400
default[:apache][:prefork][:maxclients] = 400
default[:apache][:prefork][:maxrequestsperchild] = 10000

# Worker Attributes
default[:apache][:worker][:startservers] = 4
default[:apache][:worker][:maxclients] = 1024
default[:apache][:worker][:minsparethreads] = 64
default[:apache][:worker][:maxsparethreads] = 192
default[:apache][:worker][:threadsperchild] = 64
default[:apache][:worker][:maxrequestsperchild] = 0
25 changes: 25 additions & 0 deletions cookbooks/apache2/definitions/apache_conf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Cookbook Name:: apache2
# Definition:: apache_conf
#
# Copyright 2008-2009, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

define :apache_conf do
template "#{node[:apache][:dir]}/mods-available/#{params[:name]}.conf" do
source "mods/#{params[:name]}.conf.erb"
notifies :restart, resources(:service => "apache2")
end
end
43 changes: 43 additions & 0 deletions cookbooks/apache2/definitions/apache_module.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Cookbook Name:: apache2
# Definition:: apache_module
#
# Copyright 2008-2009, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

define :apache_module, :enable => true, :conf => false do
include_recipe "apache2"

if params[:conf]
apache_conf params[:name]
end

if params[:enable]
execute "a2enmod #{params[:name]}" do
command "/usr/sbin/a2enmod #{params[:name]}"
notifies :restart, resources(:service => "apache2")
not_if do (File.symlink?("#{node[:apache][:dir]}/mods-enabled/#{params[:name]}.load") and
((File.exists?("#{node[:apache][:dir]}/mods-available/#{params[:name]}.conf"))?
(File.symlink?("#{node[:apache][:dir]}/mods-enabled/#{params[:name]}.conf")):(true)))
end
end
else
execute "a2dismod #{params[:name]}" do
command "/usr/sbin/a2dismod #{params[:name]}"
notifies :restart, resources(:service => "apache2")
only_if do File.symlink?("#{node[:apache][:dir]}/mods-enabled/#{params[:name]}.load") end
end
end
end
40 changes: 40 additions & 0 deletions cookbooks/apache2/definitions/apache_site.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Cookbook Name:: apache2
# Definition:: apache_site
#
# Copyright 2008-2009, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

define :apache_site, :enable => true do
include_recipe "apache2"

if params[:enable]
execute "a2ensite #{params[:name]}" do
command "/usr/sbin/a2ensite #{params[:name]}"
notifies :restart, resources(:service => "apache2")
not_if do
File.symlink?("#{node[:apache][:dir]}/sites-enabled/#{params[:name]}") or
File.symlink?("#{node[:apache][:dir]}/sites-enabled/000-#{params[:name]}")
end
only_if do File.exists?("#{node[:apache][:dir]}/sites-available/#{params[:name]}") end
end
else
execute "a2dissite #{params[:name]}" do
command "/usr/sbin/a2dissite #{params[:name]}"
notifies :restart, resources(:service => "apache2")
only_if do File.symlink?("#{node[:apache][:dir]}/sites-enabled/#{params[:name]}") end
end
end
end
49 changes: 49 additions & 0 deletions cookbooks/apache2/definitions/web_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Cookbook Name:: apache2
# Definition:: web_app
#
# Copyright 2008-2009, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

define :web_app, :template => "web_app.conf.erb" do

application_name = params[:name]

include_recipe "apache2"
include_recipe "apache2::mod_rewrite"
include_recipe "apache2::mod_deflate"
include_recipe "apache2::mod_headers"

template "#{node[:apache][:dir]}/sites-available/#{application_name}.conf" do
source params[:template]
owner "root"
group "root"
mode 0644
if params[:cookbook]
cookbook params[:cookbook]
end
variables(
:application_name => application_name,
:params => params
)
if File.exists?("#{node[:apache][:dir]}/sites-enabled/#{application_name}.conf")
notifies :reload, resources(:service => "apache2"), :delayed
end
end

apache_site "#{params[:name]}.conf" do
enable enable_setting
end
end
Loading

0 comments on commit 21ee3a4

Please sign in to comment.