Skip to content

Instantly share code, notes, and snippets.

@midwire
Created August 23, 2022 21:57
Show Gist options
  • Save midwire/0505c81b25534b7ab8debdd048f504be to your computer and use it in GitHub Desktop.
Save midwire/0505c81b25534b7ab8debdd048f504be to your computer and use it in GitHub Desktop.
[Capistrano - detect if a remote file exists] #ruby
def file_exists?(path)
capture(:ls, path)
true
rescue SSHKit::Command::Failed
false
end
def state_page
stage = fetch(:stage)
parts = stage.to_s.split('_')
"#{parts.first}.html"
end
def static_maintenance_page(root_path)
custom = File.join(root_path, 'lib', 'maintenance', state_page)
return custom if file_exists?(custom)
File.join(root_path, 'lib', 'maintenance', 'maintenance.html')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment