@task
def haproxy_install():
  # rsync the haproxy source.
  fprint('Rsync thirdparty/haproxy ~/haproxy')
  rsync_project(local_dir='third_party/haproxy/', remote_dir='~/haproxy/', ssh_opts='-o StrictHostKeyChecking=no')

  # build haproxy and install it in ~/bin.}
  fprint('Building haproxy')
  run('haproxy/build.sh ~/')

  # Concatenate the certificate and key into a single file (this is expected by haproxy) and push it.
  fprint('Generating viewfinder.pem for haproxy')
  vf_passphrase = load_passphrase_from_file()
  # Staging and prod use the same certs.
  local('scripts/generate_haproxy_certificate.sh viewfinder.co %s viewfinder.pem' % vf_passphrase)
  run('mkdir -p ~/conf')
  run('rm -f ~/conf/viewfinder.pem')
  put('viewfinder.pem', '~/conf/viewfinder.pem')
  run('chmod 400 ~/conf/viewfinder.pem')

  # Remove local file.
  local('rm -f viewfinder.pem')

  # Install the config files.
  fprint('Pushing haproxy configs')
  assert env.nodetype, 'no nodetype specified'
  run('ln -f -s ~/viewfinder/scripts/haproxy.conf ~/conf/haproxy.conf')
  run('ln -f -s ~/viewfinder/scripts/haproxy.redirect.%s.conf ~/conf/haproxy.redirect.conf' % env.nodetype.lower())
Install and configure haproxy.
dataset/ETHPy150Open viewfinderco/viewfinder/fabfile.py/haproxy_install