Search code examples
phprubydeploymentcapistranoapc

Referencing the current server in Capistrano task


How would I reference the current server in a Capistrano task? I want to curl a local file to clear the APC cache but the server does not listen on localhost so I need the server's IP address.

For instance,

role :web, "1.1.1.1", "2.2.2.2", "3.3.3.3"

task :clear_apc, :role => :web do
    run "curl http://#{WHAT_DO_I_PUT_HERE}/deploy/clearAPC.php"
end

What variable would I use so that when the task is run on 1.1.1.1 it curls http://1.1.1.1/deploy/clearAPC.php but when run on 2.2.2.2 it calls curls http://2.2.2.2/deploy/clearAPC.php


Solution

  • There's the magical $CAPISTRANO:HOST$

    run "curl http://$CAPISTRANO:HOST$/deploy/clearAPC.php" 
    

    should do exactly what you want.

    note: don't use it as a variable via string interpolation, capistrano will just replace the $CAPISTRANO:HOST$ in the string itself.

    That's a very weird and (afaik) undocumented feature :-)