与 Chef Solo 一起部署 Rails
Deploy Rails with Chef Solo
我正在尝试按照指南 Provisioning a Rails Server Using Chef,使用 Chef Solo 部署我的 rails 服务器设置。当我尝试 运行 部分 setup_vps.sh 时,服务器一直要求我输入 root 密码。当我 ctl-c
出来时,它要求我输入 deploy
用户的密码,但也不接受该密码。这两个用户之前都已经 ssh-copy-id
了,甚至不应该要求输入密码。
0.0.0.0.json(不是真实ip)
{
"group": "wheel",
"port": 22,
"user": {
"name": "deploy",
"password": "$mywonderfullpassword/x/"
},
"run_list": [
"recipe[main]",
"recipe[main::users]",
"recipe[main::ssh]",
"recipe[main::nodejs]",
"recipe[main::rbenv]",
"recipe[main::redis]",
"recipe[main::nginx]",
"recipe[main::app]"
]
}
setup_vps.sh
#!/bin/sh
# check for correct number of arguments
if [ $# -ne 3 ]; then
echo "Usage: [=12=] <user> <ip> <port>"
exit 1
fi
# set variables
USER=
IP=
PORT=
# upload key for root
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@$IP
# install chef
cd config/chef && knife solo prepare root@$IP
# execute the run list
knife solo cook root@$IP
# upload key for user
# ssh-copy-id -i ~/.ssh/id_rsa.pub -p $PORT $USER@$IP
# upload app
cd ../.. && cap production setup:all
# restart nginx
ssh -p $PORT -t $USER@$IP 'sudo service nginx restart'
应用食谱
# create www directory
directory '/var/www' do
user node['user']['name']
group node['group']
mode 0755
end
# create shared directory structure for app
path = "/var/www/#{node['app']}/shared/config"
execute "mkdir -p #{path}" do
user node['user']['name']
group node['group']
creates path
end
# create database.yml file
template "#{path}/database.yml" do
source 'database.yml.erb'
mode 0640
owner node['user']['name']
group node['group']
end
puma_config "#{node['app']}"
# # set unicorn config
# template "/etc/init.d/puma_#{node['app']}" do
# source 'puma.sh.erb'
# mode 0755
# owner node['user']['name']
# group node['group']
# end
#
# # add init script link
# execute "update-rc.d puma_#{node['app']} defaults" do
# not_if "ls /etc/rc2.d | grep puma_#{node['app']}"
# end
config git:(knife-solo) ✗ ./setup_server.sh deploy 0.0.0.0 22
./setup_server.sh: line 18: cd: config/chef: No such file or directory
/usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/chef-11.18.12/lib/chef/data_bag_item.rb:161: warning: circular argument reference - data_bag
Running Chef on 0.0.0.0...
Checking Chef version...
/usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:67:in `initialize': Object#timeout is deprecated, use Timeout.timeout instead.
/usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:84:in `initialize': Object#timeout is deprecated, use Timeout.timeout instead.
root@0.0.0.0's password:
Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.
deploy@0.0.0.0's password:
Permission denied, please try again.
deploy@0.0.0.0's password:
Permission denied, please try again.
deploy@0.0.0.0's password:
该指南已经过时,不推荐使用。有关更现代的示例,请参阅 https://github.com/poise/application_examples/blob/master/recipes/todo_rails.rb。
我正在尝试按照指南 Provisioning a Rails Server Using Chef,使用 Chef Solo 部署我的 rails 服务器设置。当我尝试 运行 部分 setup_vps.sh 时,服务器一直要求我输入 root 密码。当我 ctl-c
出来时,它要求我输入 deploy
用户的密码,但也不接受该密码。这两个用户之前都已经 ssh-copy-id
了,甚至不应该要求输入密码。
0.0.0.0.json(不是真实ip)
{
"group": "wheel",
"port": 22,
"user": {
"name": "deploy",
"password": "$mywonderfullpassword/x/"
},
"run_list": [
"recipe[main]",
"recipe[main::users]",
"recipe[main::ssh]",
"recipe[main::nodejs]",
"recipe[main::rbenv]",
"recipe[main::redis]",
"recipe[main::nginx]",
"recipe[main::app]"
]
}
setup_vps.sh
#!/bin/sh
# check for correct number of arguments
if [ $# -ne 3 ]; then
echo "Usage: [=12=] <user> <ip> <port>"
exit 1
fi
# set variables
USER=
IP=
PORT=
# upload key for root
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@$IP
# install chef
cd config/chef && knife solo prepare root@$IP
# execute the run list
knife solo cook root@$IP
# upload key for user
# ssh-copy-id -i ~/.ssh/id_rsa.pub -p $PORT $USER@$IP
# upload app
cd ../.. && cap production setup:all
# restart nginx
ssh -p $PORT -t $USER@$IP 'sudo service nginx restart'
应用食谱
# create www directory
directory '/var/www' do
user node['user']['name']
group node['group']
mode 0755
end
# create shared directory structure for app
path = "/var/www/#{node['app']}/shared/config"
execute "mkdir -p #{path}" do
user node['user']['name']
group node['group']
creates path
end
# create database.yml file
template "#{path}/database.yml" do
source 'database.yml.erb'
mode 0640
owner node['user']['name']
group node['group']
end
puma_config "#{node['app']}"
# # set unicorn config
# template "/etc/init.d/puma_#{node['app']}" do
# source 'puma.sh.erb'
# mode 0755
# owner node['user']['name']
# group node['group']
# end
#
# # add init script link
# execute "update-rc.d puma_#{node['app']} defaults" do
# not_if "ls /etc/rc2.d | grep puma_#{node['app']}"
# end
config git:(knife-solo) ✗ ./setup_server.sh deploy 0.0.0.0 22
./setup_server.sh: line 18: cd: config/chef: No such file or directory
/usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/chef-11.18.12/lib/chef/data_bag_item.rb:161: warning: circular argument reference - data_bag
Running Chef on 0.0.0.0...
Checking Chef version...
/usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:67:in `initialize': Object#timeout is deprecated, use Timeout.timeout instead.
/usr/local/var/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:84:in `initialize': Object#timeout is deprecated, use Timeout.timeout instead.
root@0.0.0.0's password:
Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.
deploy@0.0.0.0's password:
Permission denied, please try again.
deploy@0.0.0.0's password:
Permission denied, please try again.
deploy@0.0.0.0's password:
该指南已经过时,不推荐使用。有关更现代的示例,请参阅 https://github.com/poise/application_examples/blob/master/recipes/todo_rails.rb。