Question

I have a rails app that I inherited. In deploy.rb, it performs the following commands:

run "mv #{shared_path}/log/#{rails_env}.log #{shared_path}/log/#{rails_env}_old"
run "touch #{shared_path}/log/#{rails_env}.log && chmod -R 777 #{shared_path}/log"

So you can see it's moving the existing log file to one called _old and then creating a new one.

This causes a problem when in some situations, the first deploy fails. When I deploy again, it overwrites the _old file a second time and now the previously existing logs are gone.

The thing is, that I don't understand why the deploy script is doing this. I don't understand why it was written like this in the first place. I believe everybody would be fine if we just left the log files alone during the deploy.

Does anybody have any clues for me?

Was it helpful?

Solution

Remove it, and use log rotate.

OTHER TIPS

What the deploy script is doing is good because log files get big really soon and writing to big file is costly. You should use log rotate or some other utility. But if you want to keep it simple, give unique file names by appending timestamps

run "mv #{shared_path}/log/#{rails_env}.log #{shared_path}/log/#{rails_env}_old_#{Time.now.Time.now.to_i}"
run "touch #{shared_path}/log/#{rails_env}.log && chmod -R 777 #{shared_path}/log"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top