Thursday, July 26, 2007

How to change the timestamp of a file



I ran in to this problem when moving log files around that the timestamp on some of the files changed. And just for consistence I wanted to change the timestamp of these files..

I found that you can specify the data using the touch command, like this:

[heimdull@hostname ~]# touch -t 200709280930 httpd.conf
[heimdull@hostname ~]# ll httpd.conf
-rw-r–r– 1 root root 1558 Sep 28 2007 httpd.conf
[heimdull@hostname ~]#

If you don’t want to change all the timestamps of the file use these options:
-a change only the access time
-m change only the modification time

View the access timestamp(last time the file was accessed)

ls -ul httpd.conf

View the modification time(Last time the files was changed)

ls -tl httpd.conf

Sunday, July 1, 2007

Capistrano with multiple environments



A few months ago I started poking around with Capistrano and now cap is all I use everywhere… This thing rocks. The first problem I had was multiple environments, we have Production, Staging, performance, integration, qa1,qa2,stability1 and stability2 ?!?! dude can you say excessive.. anyways heres how I managed around this:

This goes in your deploy.rb file:

desc "Set the target stage to production"
task :production do
before “deploy”, “mysql:backup”
set :deploy_via, :rsync_with_remote_cache
set :stage, “#{current_task.name.to_s}”
role :web, “192.168.1.1″, :ssl => true
role :app, “192.168.1.2″
role :db, “192.168.1.3″, :primary => true
role :db, “192.168.1.4″, :no_release => true, :replica => true
role :db, “192.168.1.5″, :no_release => true, :replica => true
end
desc “Set the target stage to staging”
task :staging do
before “deploy”, “mysql:backup”
set :deploy_via, :rsync_with_remote_cache
set :stage, “#{current_task.name.to_s}”
role :web, “192.168.2.1″, :ssl => true
role :app, “192.168.2.2″
role :db, “192.168.2.3″, :primary => true
end

desc "Set the target stage to perf"
task :perf do
set :stage, “#{current_task.name.to_s}”
role :web, “192.168.3.1″, :ssl => true
role :app, “192.168.3.2″
role :db, “192.168.3.3″, :primary => true
end

I think this worked better than the multi-stage extension the was added to Capistrano. (It’s very similar except you put all the stages in their own files.)

Now when you call a task add the environment

cap production deploy:cold

I also have two different ways of deploying since the production servers are behind a firewall I added the :deploy_via in the task which overrides the deploy method and uses rsync for these hosts. (Btw there is a bug in the rsync code which I blogged about here)