Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I properly manage the rails tmp directory?

After I deploy a rails application in production mode, do I need to schedule a periodic cleanup of the rails tmp directory? aka: rake tmp:clear (or its sub-parts tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear).

I know a few major revisions of rails back this was something that was needed to be done. I'm currently using Rails 4.1.x. Thanks.

like image 221
Super Dave Avatar asked Feb 13 '15 04:02

Super Dave


Video Answer


1 Answers

Add one or more of those to your crontab file and that should do it for you...

rake tmp:cache:clear              
rake tmp:clear                     
rake tmp:create                     
rake tmp:sessions:clear              
rake tmp:sockets:clear   

Keep in mind, clearing sessions will kill all active sessions to. I don't recommend that. You could create a model called:

Periodic with something like this in it:

def self.run
      CGI::Session::ActiveRecordStore::Session.
        destroy_all( ['updated_at <?', 48.hours.ago] )
  end

then cron your script/runner like this

script/runner -e production Periodic.run
like image 70
Joe Sebin Avatar answered Oct 22 '22 23:10

Joe Sebin