ror笔记2

ror 学习笔记2




rails appconfig 文件夹中新建unicorn.rb内容如下


worker_processes 2

working_directory "/home/mage/boleht"

listen "/tmp/unicorn.boleht.sock"

listen 19555, :tcp_nopush => true

timeout 120

pid "/home/mage/boleht/tmp/pids/unicorn.pid"

stderr_path "/home/mage/boleht/log/unicorn.stderr.log"

stdout_path "/home/mage/boleht/log/unicorn.stdout.log”


rail app 根目录新建unicorn.sh

UNICORN=/usr/local/ruby/bin/unicorn_rails

killall -9  unicorn_rails

$UNICORN -D -c /home/mage/boleht/config/unicorn.rb


参考

使用Nginx + unicorn搭建ruby on rails的生产环境



nginx启动、重启、关闭

一、启动  


cd usr/local/nginx/sbin

./nginx

二、重启

  更改配置重启nginx  

kill -HUP 主进程号或进程号文件路径

或者使用

cd /usr/local/nginx/sbin

./nginx -s reload

    判断配置文件是否正确 

nginx -t -c /usr/local/nginx/conf/nginx.conf

或者

cd /usr/local/nginx/sbin

./nginx -t

三、关闭

  查询nginx主进程号

  ps -ef | grep nginx

  从容停止   kill -QUIT 主进程号

  快速停止   kill -TERM 主进程号

  强制停止   kill -9 nginx

  若nginx.conf配置了pid文件路径,如果没有,则在logs目录下

  kill -信号类型 '/usr/local/nginx/logs/nginx.pid'

四、升级

  1、先用新程序替换旧程序文件

  2kill -USR2 旧版程序的主进程号或者进程文件名

    此时旧的nginx主进程会把自己的进程文件改名为.oldbin,然后执行新版nginx,此时新旧版本同时运行

  3kill -WINCH 旧版本主进程号

  4、不重载配置启动新/旧工作进程

    kill -HUP /新版本主进程号

    从容关闭旧/新进程

    kill -QUIT /新进程号

    快速关闭旧/新进程

    kill -TERM /新进程号





unicorn + nginx 搞定之后======================


rails-api new myapp -d mysql —skip-bundle


vi G

 

vi conf/database.yml


rails g scaffold task\

>空格 uid:string name:string


不要用id做字段名


rake db:create 


rake db:migrate


scp -r myapp root@115.28.232.242


bundle install 


rails-api server -b 115.28.232.242


front html 


=====================================


yum install nginx


service nginx start  

service nginx stop

service nginx reconfigure

service nginx status




gem install unicorn



写一个unicorn.rb配置文件 放入ror工程的config文件夹


worker_processes 1

 working_directory "/home/mage/jdwy" 

 

listen "/var/tmp/.unicorn.sock", :backlog => 64

listen 19527, :tcp_nopush => true        

 

timeout 120

 

pid "/home/mage/jdwy/tmp/pids/unicorn.pid"    

 

stderr_path "/home/mage/jdwy/log/unicorn.stderr.log"    

stdout_path "/home/mage/jdwy/log/unicorn.stdout.log"    

 

preload_app true

GC.respond_to?(:copy_on_write_friendly=) and

  GC.copy_on_write_friendly = true

 

check_client_connection false

 

before_fork do |server, worker|

  defined?(ActiveRecord::Base) and

    ActiveRecord::Base.connection.disconnect!

end

 

after_fork do |server, worker|

  defined?(ActiveRecord::Base) and

    ActiveRecord::Base.establish_connection

end


在写一个.sh文件,每次一句话启动unicorn  


UNICORN=/usr/local/ruby/bin/unicorn_rails

killall -9  unicorn_rails

$UNICORN -c /home/mage/jdwy/config/unicorn.rb -D -E production





nginx启动,重启,关闭命令

停止操作

停止操作是通过向nginx进程发送信号(什么是信号请参阅linux文 章)来进行的

步骤1:查询nginx主进程号

ps -ef | grep nginx

在进程列表里 面找master进程,它的编号就是主进程号了。

步骤2:发送信号

从容停止Nginx

kill -QUIT 主进程号

快速停止Nginx

kill -TERM 主进程号

强制停止Nginx

pkill -9 nginx


另外, 若在nginx.conf配置了pid文件存放路径则该文件存放的就是Nginx主进程号,如果没指定则放在nginxlogs目录下。有了pid文 件,我们就不用先查询Nginx的主进程号,而直接向Nginx发送信号了,命令如下:

kill -信号类型 '/usr/nginx/logs/nginx.pid'


平滑重启

如果更改了配置就要重启Nginx,要先关闭Nginx再打开?不是的,可以向Nginx 发送信号,平滑重启。

平滑重启命令:

kill -HUP 住进称号或进程号文件路径

或者使用

/usr/nginx/sbin/nginx -s reload



注意,修改了配置文件后最好先检查一下修改过的配置文件是否正 确,以免重启后Nginx出现错误影响服务器稳定运行。判断Nginx配置是否正确命令如下:

nginx -t -c /usr/nginx/conf/nginx.conf

或者

/usr/nginx/sbin/nginx -t




每次kill 端口号,来关闭unicorn服务,也可以用来关闭nginx



rails new used school

rails g scaffold Item title:string description:text --skip-stylesheets

rake db:migrate

修改Gemfile文件,加入要安装的bootstrap相关包


5、安装相关包

bundle install

运行


rails g bootstrap:install


生成bootstrap相关文件

rails g bootstrap:themed items -f




跳转备忘


页面跳转用

<%= link_to "GoodBye!", :action => "project" %> 

此处action是默认根control中的方法(约定),可以从文件夹路径中看得 


#没有动态数据,只有模版,报错

   #render :action => "index"

   #render 'dpub/index.html.erb'

   

   #有动态数据,就可以

   @posts = Post.all

   @pmen = Pman.all

   render 'dpub/homepage/_hot_project.html.erb'

   

   

   # 纯静态可以

   # render 'dpub/homepage/_foot.html.erb’ 


嵌套的erb可以复用父控制器里的model,而且不用import,自动感知


任何一个control 可以随便拿任何一个model(约定)






部署的时候装不上therubyracer,删掉所有的libv8therubyracer,用一下

gem install libv8 -v 3.16.14.7 -- --with-v8-lib

gem install therubyracer





<%=DateTime.parse(cgstate.uptime.to_s).strftime('%Y-%m').to_s %>











posted @ 2015-06-17 20:38  梅西爸爸  阅读(198)  评论(0编辑  收藏  举报